Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🐍 Unit 2 – Python Programming  ·  Lesson 05

Operators, Input-Output & Debugging

Operators in Python

An operator is a symbol that tells Python to do a calculation or comparison on values called operands. Shops, banks and schools use these every day — adding GST, comparing marks, checking eligibility.

➕
Arithmetic+ - * / // % **
⚖️
Relational== != > < >= <=
🔗
Logicaland or not
📝
Assignment= += -= *= /=
🔍
Membershipin not in
🆔
Identityis is not
Operator families

Arithmetic operators

Python
price, gst = 1250, 18
tax = price * gst / 100
print('GST =', tax, '| Total =', price + tax)
print(29 // 4, 29 % 4, 2 ** 10, 9 / 2)
minutes = 135
print(minutes // 60, 'h', minutes % 60, 'min')
GST = 225.0 | Total = 1475.0 7 1 1024 4.5 2 h 15 min
OperatorNameExampleResult
+Addition1250 + 2251475
-Subtraction50 - 1238
*Multiplication45.5 * 3136.5
/Division9 / 24.5
//Floor division29 // 47
%Modulus (remainder)29 % 41
**Exponent2 ** 101024
Arithmetic operators with results

Relational, logical and membership operators

Relational operators compare values and return True or False. Logical operators combine conditions. Membership operators check if a value is present in a string, list or other collection.

Python
marks, attendance = 72, 68
print(marks >= 33, attendance >= 75)
eligible = marks >= 33 and attendance >= 75
print('Eligible for exam:', eligible)
print(10 > 3 or 5 < 2, not 10 > 3)
print('IP' in 'Informatics Practices', 'ip' in 'Informatics Practices')
True False Eligible for exam: False True False False False

Note that 'IP' in 'Informatics Practices' is False — the capital letters "IP" do not appear together; membership is case-sensitive.

Assignment operators

Python
stock = 50
stock -= 12      # 12 sold
stock += 30      # 30 arrived
stock *= 2       # second branch has the same
print('Stock =', stock)
Stock = 136

Expressions and precedence

An expression is a combination of operands and operators that gives one value. When many operators appear, Python follows precedence: brackets first, then **, then * / // %, then + -, then comparisons, then not, and, or. Operators of the same level work left to right, except ** which works right to left.

Python
print(5 + 3 * 2 - 8 / 4)
print((5 + 3) * 2)
print(2 ** 2 ** 3)
print(15 - 6 // 4)
9.0 16 256 14
5 + 3 * 2 - 8 / 4start5 + 6 - 8 / 43 * 2 first5 + 6 - 2.08 / 4 next11 - 2.0left to right9.0result (float because of /)
Step-by-step evaluation

Input and output

input(prompt) reads text typed by the user. print() displays values; use sep and end to control spacing.

Python
name = input('Customer name: ')
amount = float(input('Purchase amount: '))
if amount > 2000:
    discount = amount * 10 / 100
else:
    discount = amount * 5 / 100
print('Dear', name + ', you pay Rs.', amount - discount)
Customer name: Pooja Purchase amount: 2400 Dear Pooja, you pay Rs. 2160.0

Type conversion

Implicit conversion is automatic (int + float → float). Explicit conversion (type casting) uses int(), float(), str(), bool().

Python
a = '5'
print(a * 3, int(a) * 3)                  # string repeat vs number multiply
print(int(9.99), float('12'), str(3.0), int('0012'))
print(round(1234.5678, 2), round(1234.5678, -2))
555 15 9 12.0 3.0 12 1234.57 1200.0
Python
c = float(input('Temperature in Celsius: '))
f = c * 9 / 5 + 32
print('Fahrenheit =', round(f, 2))
Temperature in Celsius: 36.6 Fahrenheit = 97.88

Errors and debugging

Runtime error – program stops

  • Dividing by zero
  • Using a variable that was never created
  • Converting "abc" with int()
  • Python shows the error name and line

Logical error – wrong answer

  • Program finishes without any message
  • Wrong formula or forgotten conversion
  • Found only by checking the output
  • Hardest to find
Two errors that appear only when you run the program
Python
total = 450
items = 0
print('Average price:', total / items)
ZeroDivisionError: division by zero

A classic logical error — forgetting to convert input. The user types 3, so the "total" should be 120, but the string "3" is repeated 40 times:

Python
qty = input('Quantity: ')
print('Total:', qty * 40)       # bug: qty is a string!
Quantity: 3 Total: 3333333333333333333333333333333333333333

Fix: qty = int(input('Quantity: ')). Debug by printing variables and their types: print(qty, type(qty)).

Summary & practice

  • Arithmetic: + − * / // % **; relational give True/False; logical: and, or, not.
  • Precedence: () → ** → * / // % → + − → comparisons → not → and → or.
  • input() returns str; convert with int()/float().
  • Errors: syntax, runtime, logical.
✅ Practice

1) Evaluate 20 - 3 ** 2 // 4 * 2. 2) Write a program to input the cost price and selling price and print profit or loss amount and percentage. 3) Write a program to convert seconds into hours, minutes and seconds.

Answer 1: 3 ** 2 = 9 → 9 // 4 = 2 → 2 * 2 = 4 → 20 − 4 = 16.

Frequently Asked Questions

What does the // operator do?
Floor division: it divides and gives the quotient rounded down to a whole number. 29 // 4 is 7.
Why must input be converted with int() or float()?
input() returns text. Without conversion "3" * 40 repeats the text 40 times instead of multiplying, and "25" + "5" gives "255".
What are the three types of errors?
Syntax errors (code breaks Python rules), runtime errors (program crashes while running, like division by zero) and logical errors (program runs but gives a wrong result).
← Class 11 Informatics Practices
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicFunctions & if-elif-else Your progress: 5 / 20 (25%) · Lesson 6 / 20 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free