Home » Tech Tutorials » Coding & Programming » Python » Practical Operator Programs

Practical Operator Programs

Practical Operator Programs

Pythonలో operators ను కేవలం విడిగా నేర్చుకోవడం కాకుండా, చిన్న చిన్న practical programs లో ఉపయోగించడం చాలా ముఖ్యం. ఈ lessonలో arithmetic, assignment, comparison మరియు logical operators ను కలిపి ఉపయోగిస్తాము.

Operators ఎందుకు ఉపయోగిస్తాము?

Operators ద్వారా calculations చేయవచ్చు, values ను compare చేయవచ్చు, conditions యొక్క result తెలుసుకోవచ్చు మరియు variables లో values update చేయవచ్చు.

ఈ lessonలో నేర్చుకునే practical uses

  • Marks యొక్క total మరియు average కనుగొనడం
  • Shopping bill మరియు tax లెక్కించడం
  • ఒక వ్యక్తి age ఆధారంగా comparison చేయడం
  • రెండు conditions ను logical operators తో కలపడం

Operators ఉపయోగించే విధానం

ముందుగా values ను variables లో store చేయాలి. తరువాత operators ఉపయోగించి కొత్త result ను variable లో store చేయాలి. చివరగా print() ద్వారా result చూపించాలి.

Simple Explanation

Arithmetic operators calculations కోసం ఉపయోగిస్తాము. ఉదాహరణకు + addition, - subtraction, * multiplication మరియు / division కోసం ఉపయోగిస్తాము.

Assignment operators variables కు values ఇవ్వడానికి లేదా వాటి values ను update చేయడానికి ఉపయోగిస్తాము. ఉదాహరణకు = మరియు +=.

Comparison operators రెండు values ను compare చేసి True లేదా False ఇస్తాయి.

Logical operators రెండు లేదా అంతకంటే ఎక్కువ comparison results ను కలపడానికి ఉపయోగిస్తాము. and operatorలో అన్ని conditions True అయితేనే result True అవుతుంది.

Practical program రాయేటప్పుడు values, calculation steps మరియు final output ను స్పష్టంగా ఉంచాలి.

Real-Life Example

ఒక shopలో ఒక notebook ధర 250 రూపాయలు, quantity 3 అని అనుకుందాం. ముందుగా price ను quantityతో multiply చేసి subtotal కనుగొంటాము. తరువాత subtotal పై tax లెక్కించి, subtotalకు tax కలిపి final bill కనుగొంటాము. ఈ programలో multiplication, addition మరియు assignment operators ఉపయోగిస్తాము.

Code Examples

Example 1: Student Marks Total and Average

math_marks = 80
science_marks = 75
english_marks = 85
total = math_marks + science_marks + english_marks
average = total / 3
print("Total:", total)
print("Average:", average)

మూడు subjects marks ను variablesలో store చేసి, arithmetic operators ఉపయోగించి total మరియు average లెక్కిస్తున్నాము.

Total: 240
Average: 80.0

Example 2: Shopping Bill with Tax

price = 250
quantity = 3
subtotal = price * quantity
tax = subtotal * 0.05
total = subtotal + tax
print("Subtotal:", subtotal)
print("Tax:", tax)
print("Total:", total)

ఒక వస్తువు price మరియు quantity ఆధారంగా subtotal, 5 percent tax మరియు final total bill ను లెక్కిస్తున్నాము.

Subtotal: 750
Tax: 37.5
Total: 787.5

Example 3: Comparison and Logical Operators

age = 20
has_id = True
print("Eligible by age:", age >= 18)
print("Can enter:", age >= 18 and has_id)

Comparison operatorతో age check చేసి, logical operatorతో age check మరియు identity card check రెండింటినీ కలుపుతున్నాము.

Eligible by age: True
Can enter: True

Line-by-Line Explanation

math_marks = 80
ఈ lineలో Mathematics marksను 80గా store చేస్తున్నాము. Python ఈ valueను math_marks variableలో ఉంచుతుంది.
science_marks = 75
Science marksను science_marks variableలో store చేస్తున్నాము.
english_marks = 85
English marksను english_marks variableలో store చేస్తున్నాము.
total = math_marks + science_marks + english_marks
ఇక్కడ + operatorతో మూడు marksను కలుపుతున్నాము. వచ్చిన total valueను total variableలో store చేస్తుంది.
average = total / 3
Total marksను subjects సంఖ్య అయిన 3తో divide చేస్తున్నాము. వచ్చిన average valueను average variableలో store చేస్తుంది.
print(“Total:”, total)
ఈ line total అనే labelతో పాటు total variable valueను screenపై చూపిస్తుంది.
print(“Average:”, average)
ఈ line average అనే labelతో పాటు average valueను screenపై చూపిస్తుంది.
price = 250
ఒక వస్తువు ధరను price variableలో 250గా store చేస్తున్నాము.
quantity = 3
కొనుగోలు చేయాల్సిన వస్తువుల సంఖ్యను quantity variableలో store చేస్తున్నాము.
subtotal = price * quantity
price మరియు quantityను * operatorతో multiply చేసి subtotalను లెక్కిస్తున్నాము.
tax = subtotal * 0.05
Subtotalలో 5 percentను లెక్కించడానికి subtotalను 0.05తో multiply చేస్తున్నాము.
total = subtotal + tax
Subtotal మరియు taxను + operatorతో కలిపి final billను total variableలో store చేస్తున్నాము.
print(“Subtotal:”, subtotal)
Subtotal amountను screenపై చూపిస్తుంది.
print(“Tax:”, tax)
Tax amountను screenపై చూపిస్తుంది.
print(“Total:”, total)
Final total bill amountను screenపై చూపిస్తుంది.
age = 20
వ్యక్తి ageను age variableలో 20గా store చేస్తున్నాము.
has_id = True
వ్యక్తి దగ్గర identity card ఉందని సూచించడానికి Boolean value Trueను store చేస్తున్నాము.
print(“Eligible by age:”, age >= 18)
>= operatorతో age 18 లేదా అంతకంటే ఎక్కువా అని check చేస్తున్నాము. Result True లేదా Falseగా వస్తుంది.
print(“Can enter:”, age >= 18 and has_id)
age >= 18 మరియు has_id అనే రెండు conditionsను and operatorతో కలుపుతున్నాము. రెండూ True కావడంతో final result True అవుతుంది.

Try It

Try this Python code:

Example

price = 100
quantity = 4
subtotal = price * quantity
tax = subtotal * 0.10
total = subtotal + tax
print("Subtotal:", subtotal)
print("Tax:", tax)
print("Total:", total)

Try It Yourself »

Practice

Practice: ఒక rectangle యొక్క length 12 మరియు width 5. Arithmetic operators ఉపయోగించి area మరియు perimeterను calculate చేసి print చేయండి.

Hint: Area = length * width. Perimeter = 2 * (length + width).

Practice: ఒక product ధర 500 మరియు quantity 2. Subtotalను calculate చేసి, 10 percent tax కలిపి final totalను print చేయండి.

Hint: ముందుగా subtotal = price * quantity. తరువాత tax = subtotal * 0.10.

Common Mistakes

Average calculate చేసేటప్పుడు totalను subjects సంఖ్యతో divide చేయకుండా తప్పు సంఖ్యతో divide చేయడం.
ఎన్ని values కలిపారో ఆ values సంఖ్యతో divide చేయండి. మూడు subjects ఉంటే total / 3 ఉపయోగించండి.
Multiplication కోసం x ఉపయోగించడం.
Pythonలో multiplication కోసం తప్పనిసరిగా * operator ఉపయోగించాలి.
Comparison కోసం = ఉపయోగించడం.
Value assign చేయడానికి = ఉపయోగించాలి. Compare చేయడానికి ==, >= లేదా ఇతర comparison operators ఉపయోగించాలి.
Taxను subtotalకు కలపకుండా tax amountను మాత్రమే final totalగా print చేయడం.
Final bill కోసం total = subtotal + tax అని రాయాలి.
and ఉపయోగించినప్పుడు ఒక condition True అయితే సరిపోతుందని అనుకోవడం.
and result True కావాలంటే దానిలోని అన్ని conditions True కావాలి.

Interview Questions

Pythonలో arithmetic operators ఎందుకు ఉపయోగిస్తారు?

Answer: Addition, subtraction, multiplication, division వంటి mathematical calculations చేయడానికి arithmetic operators ఉపయోగిస్తారు.

Comparison operator result ఏ data typeలో వస్తుంది?

Answer: Comparison operator result సాధారణంగా Boolean valueగా వస్తుంది. అది True లేదా False అవుతుంది.

and operator ఎప్పుడు True ఇస్తుంది?

Answer: and operatorలో ఉన్న అన్ని conditions True అయినప్పుడు మాత్రమే result True అవుతుంది.

Shopping bill programలో subtotal మరియు total మధ్య తేడా ఏమిటి?

Answer: Subtotal అనేది product price మరియు quantity ఆధారంగా వచ్చిన amount. Total అనేది subtotalకు tax వంటి అదనపు amountలు కలిపిన final amount.

Exam Questions

ఈ expression result ఏమిటి: 10 + 5 * 2?

Answer:

Result 20. Multiplicationకు addition కంటే ఎక్కువ precedence ఉంటుంది.

ఈ expression result ఏమిటి: 25 >= 18?

Answer:

Result True, ఎందుకంటే 25 అనేది 18 కంటే ఎక్కువ.

ఒక product price 50, quantity 4 అయితే subtotal కనుగొనే Python statement రాయండి.

Answer:

subtotal = 50 * 4

True and False result ఏమిటి?

Answer:

Result False, ఎందుకంటే and operatorలో అన్ని values True కావాలి.

Quick Revision

  • Arithmetic operators calculations కోసం ఉపయోగిస్తాము.
  • Variablesలో values store చేసి operatorsతో కొత్త results calculate చేయవచ్చు.
  • Comparison operators True లేదా False ఇస్తాయి.
  • and operator True కావాలంటే అన్ని conditions True కావాలి.
  • Shopping billలో subtotal, tax మరియు totalను వేర్వేరుగా calculate చేయడం మంచిది.
  • Operator precedence వల్ల expressionలో operations ఒక నిర్దిష్ట క్రమంలో execute అవుతాయి.

Test Your Knowledge

Take a short quiz based on this lesson.

10 Questions • Results
Scroll to Top