🐍 Python for Everyone

← Back to the quiz

Chapter 3 Exercises 15 min, hands-on

Exercises: Operators

How to run these Download starter.py below, then run python3 starter.py.

1 All seven arithmetic operators

Given a = 17 and b = 5, print the result of +, -, *, /, //, %, and **.

2 Range check

Given age = 25, check whether it's between 18 and 65 (inclusive) using a single expression with and.

3 Bitwise practice

Given x = 12 and y = 10, print x & y, x | y, and x ^ y.

🐞 Task 4 — Debug the Code

This code is supposed to print the exact average of 7 and 2 (which is 3.5), but it always prints 3. Find and fix the bug.

buggy.py
total = 7
count = 2
average = total // count
print("Average:", average)
← Back to Quiz Practice Bank →