PART 1 โ€ข LEVEL 03

โž— Operators & Expressions

Learn how Python combines values, performs calculations, compares results and builds logical decisions while following precise precedence rules.

โฑ 80โ€“95 minutes๐Ÿ“š 8 concepts๐Ÿ’ป 5 programs๐Ÿง  6-question quiz
score_check.pyPython 3
theory = 78
lab = 86
average = (theory + lab) / 2
eligible = average >= 60 and lab >= 70

print(f"Average: {average}")
print(f"Eligible: {eligible}")
OUTPUTAverage: 82.0
Eligible: True

By the End of This Level

You will be able to construct and evaluate Python expressions accurately.

01

Use arithmetic and assignment operators correctly.

02

Predict results using precedence and associativity.

03

Build comparison and logical expressions.

04

Recognize membership and identity operations.

01

Operators, Operands and Expressions

An operator tells Python which operation to perform. The values used by the operator are operands, and their complete combination is an expression.

In total = price * quantity, price and quantity are operands, * is the operator, and price * quantity is the expression whose result is assigned to total.

Expression

A valid combination of values, variables, operators and function calls that Python evaluates to produce one value.

Arithmetic12 + 8 โ†’ 20
Comparison75 >= 40 โ†’ True
LogicalTrue and False โ†’ False
Membership"Py" in "Python" โ†’ True
02

Arithmetic Operators

OperatorMeaningExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiplication10 * 330
/True division10 / 33.333...
//Floor division10 // 33
%Remainder10 % 31
**Exponentiation10 ** 31000
EXAMPLE 1

Split Total Seconds

total_seconds = 3672
hours = total_seconds // 3600
remaining = total_seconds % 3600
minutes = remaining // 60
seconds = remaining % 60

print(hours, minutes, seconds)
OUTPUT
1 1 12
Division detail

/ returns a floating-point result. // returns the mathematical floor, so negative values may move to the next smaller integer: -7 // 2 is -4.

03

Precedence and Associativity

Precedence decides which kind of operator is evaluated first. Associativity decides the direction when operators have the same precedence.

1Parentheses( )
โ†’
2Exponent**
โ†’
3Multiply / Divide* / // %
โ†’
4Add / Subtract+ -
EXAMPLE 2

Trace the Expression

result = 10 + 2 * 3 ** 2
print(result)

grouped = (10 + 2) * 3 ** 2
print(grouped)
OUTPUT
28
108
DEFAULT PRECEDENCE
10 + 2 * 3
# 10 + 6
# 16

Multiplication runs before addition.

EXPLICIT GROUPING
(10 + 2) * 3
# 12 * 3
# 36

Parentheses make the intended order unmistakable.

04

Comparison Operators

A comparison expression evaluates to the Boolean value True or False.

OperatorQuestionExampleResult
==Are they equal?5 == 5True
!=Are they different?5 != 3True
>Greater than?8 > 10False
<Less than?8 < 10True
>=Greater than or equal?40 >= 40True
<=Less than or equal?12 <= 9False
Do not confuse them

= assigns a value, while == compares two values for equality.

05

Logical Operators

๐Ÿ”—

and

True only when both operands are true.

๐Ÿ”€

or

True when at least one operand is true.

๐Ÿ”„

not

Reverses the truth value of its operand.

โšก

Short-circuiting

Python stops as soon as the final logical result is known.

EXAMPLE 3

Training Eligibility

attendance = 82
test_score = 68
fees_due = False

eligible = attendance >= 75 and test_score >= 60
blocked = fees_due or not eligible

print("Eligible:", eligible)
print("Blocked:", blocked)
OUTPUT
Eligible: True
Blocked: False
06

Assignment Operators

Augmented assignment performs an operation and stores the result back in the same variable.

Long formShort formMeaning
score = score + 5score += 5Add and assign
stock = stock - 1stock -= 1Subtract and assign
price = price * 2price *= 2Multiply and assign
value = value / 10value /= 10Divide and assign
count = count % 5count %= 5Remainder and assign
EXAMPLE 4

Update a Learning Score

score = 50
score += 20
score -= 5
score *= 2

print(score)
OUTPUT
130
07

Membership and Identity Operators

IDENTITY

is and is not

Check whether two references point to the same object.

result = None
print(result is None)   # True
BEST PRACTICE

Equality vs Identity

Use == for equal values. Use is mainly for singleton objects such as None.

score == 100
result is None

Common Operator Mistakes

Assignment
score = 50

Use ==, not =, when you intend to compare values.

Precedence
total / count + 1

Add parentheses when the required grouping is total / (count + 1).

Logic
age >= 18 or score >= 60

Use and if both requirements must be satisfied.

Evaluate safely:1. Mark operands2. Apply parentheses3. Follow precedence4. Check intermediate types5. Verify the result
QUICK REVISION

๐Ÿ“Œ Operators & Expressions โ€” Quick Revision

Review the complete Level 3 lesson before attempting the quiz and programming problems.

01

An expression evaluates to a single value.

02

/ performs true division; // performs floor division.

03

% produces a remainder and ** performs exponentiation.

04

Parentheses provide the clearest control over evaluation order.

05

Exponentiation is evaluated before multiplication and addition.

06

Comparisons produce True or False.

07

and requires both conditions; or requires at least one.

08

not reverses a truth value.

09

Augmented assignment updates and stores a value concisely.

10

Use == for equality and is mainly with None.

Level 3 Quick Quiz

Select one answer for every question, then check your score.

6 Questions
1What is the result of 17 // 5?
2What is 2 + 3 * 4?
3Which operator compares two values for equality?
4What is True and not False?
5Which statement is equivalent to score = score + 10?
6Which is recommended for checking whether result has no value?

PRACTICE

๐ŸŽฏ 5 Programming Problems โ€” Operators & Expressions

Use the displayed sample inputs. Write expressions carefully, run them, and check the exact expected output before viewing the official program.

๐Ÿ“ˆ Operators Practice Progress
Solved0 / 5
Completed with Solution0
Total Score0 / 500
Completion0%

A problem counts as Solved when its output passes before the official solution is opened.

1. CodeBhavya Book Bill

Read the price and quantity, then display the total bill.

Sample input: 120, 3Expected output: Total = 360
2. Average of Three Marks

Read three marks and display their arithmetic average.

Sample input: 78, 85, 92Expected output: Average = 85
3. Simple Interest

Read principal, annual rate and time, then calculate simple interest.

Sample input: 10000, 5, 2Expected output: Simple interest = 1000
4. Seconds into Time

Convert total seconds into hours, minutes and remaining seconds.

Sample input: 3672Expected output: Three labelled lines: 1, 1, 12
5. Training Eligibility

A student is eligible when age is at least 18 and score is at least 60. Display the Boolean result.

Sample input: 20, 75Expected output: Eligible = True
KEY TAKEAWAY

๐ŸŽฏ Make Every Expression Intentional

1Identify

Know each operand and its data type.

โ†’
2Group

Use parentheses to express the intended order.

โ†’
3Evaluate

Follow precedence one operation at a time.

โ†’
4Verify

Check both the result and its type.

Correct expressions are not guesses. They are small, traceable calculations whose operands, operators and evaluation order are all understood.

INTERACTIVE LEARNING

๐ŸŽฌ Expression Evaluation โ€” Visual Flow

Watch Python reduce 10 + 2 * 3 ** 2 one precedence level at a time.

PROGRAM TRACING

๐Ÿ”Ž Program Tracing โ€” Operator Results

Trace arithmetic, remainder and comparison results as variables and output change.

INTERVIEW PREPARATION

๐ŸŽค Operators & Expressions โ€” Interview Questions

Answer aloud before opening each explanation.

1.

What is the difference between / and //?

2.

What is operator precedence?

3.

What is associativity?

4.

How do and and or differ?

5.

What is short-circuit evaluation?

6.

When should is be used instead of ==?

EXTRA TIPS

๐Ÿ’ก Operators & Expressions โ€” Extra Tips

  • 01

    Use parentheses when they make the intended formula easier to read, even if precedence already gives the same result.

  • 02

    Trace one intermediate value at a time when an expression produces an unexpected answer.

  • 03

    Remember that / returns a float even when the division is exact.

  • 04

    Use // and % together when splitting a total into units and remainders.

  • 05

    Write complete comparisons on both sides of logical operators.

  • 06

    Prefer clear Boolean variable names such as is_eligible or has_access.

EXTRA PRACTICE

โœ๏ธ Operators & Expressions โ€” Extra Practice Questions

  1. Predict 5 + 2 * 3 ** 2 without running it, then verify your trace.
  2. Read two numbers and display all seven arithmetic-operation results.
  3. Read a three-digit number and display the sum of its digits using // and %.
  4. Convert a total number of minutes into hours and remaining minutes.
  5. Write an expression that checks whether a number lies from 10 through 50, inclusive.
  6. Show how parentheses change the result of 20 - 6 / 2 + 3.
  7. Use augmented assignment to apply a bonus, penalty and multiplier to a score.
  8. Check whether the text "Python" contains "tho".
  9. Build a Boolean expression for age at least 18, attendance at least 75 and no pending fee.
  10. Explain why 2 ** 3 ** 2 is different from (2 ** 3) ** 2.

Operators & Expressions Complete

When you can predict precedence, choose suitable operators and solve all five programs without help, mark this level complete and continue.