Python · Python Fundamentals

Operators — Practice Questions

50 questions. Try each one yourself before checking the answer.

Q1ArithmeticEasy

Create two variables a = 15 and b = 4. Print the result of a + b.

Q2ArithmeticEasy

Using the same a = 15 and b = 4, print the result of a - b.

Q3ArithmeticEasy

Using a = 15 and b = 4, print the result of a * b.

Q4ArithmeticEasy

Using a = 15 and b = 4, print both a / b (true division) and a // b (floor division), each with a label.

Q5ArithmeticEasy

Using a = 15 and b = 4, print the result of a % b (the remainder).

Q6ArithmeticEasy

Create base = 2 and exponent = 10. Print base ** exponent.

Q7AssignmentEasy

Create x = 10. Use the += operator to add 5 to it, then print x.

Q8ComparisonEasy

Create a = 5 and b = 8. Print the results of a == b and a != b.

Q9ComparisonEasy

Create a = 7 and b = 3. Print the results of a > b, a < b, a >= b, and a <= b.

Q10LogicalEasy

Create two booleans, is_sunny = True and is_weekend = False. Print the results of is_sunny and is_weekend, is_sunny or is_weekend, and not is_sunny.

Q11AssignmentMedium

Start with value = 100. Apply -=20, then *=2, then /=4, printing value after each step.

Q12AssignmentMedium

Start with value = 17. Apply //=3, then **=2, then %=5, printing value after each step.

Q13ComparisonMedium

Ask the user for two numbers and print whether the first is greater than the second.

Q14LogicalMedium

Ask the user for their age and print a boolean is_teen that is True only if the age is between 13 and 19 inclusive, using and.

Q15MembershipMedium

Create word = "python". Print whether "y" is in the word.

Q16MembershipMedium

Using the same word = "python", print whether "z" is not in the word.

Q17MembershipMedium

Create a list allowed_ids = [101, 102, 103]. Print whether 105 is in that list.

Q18IdentityMedium

Create list1 = [1, 2, 3] and list2 = [1, 2, 3]. Print list1 == list2 and list1 is list2. Why do they differ?

Q19IdentityMedium

Create value = None. Print value is None and value == None. Which one is the idiomatic way to check for None, and why?

Q20PrecedenceMedium

Evaluate 10 + 2 * 3 and print the result. Add a comment explaining the order of operations.

Q21Real-WorldMedium

Ask the user for a cart total and print a boolean qualifies_for_free_shipping that is True when the total is over 500.

Q22Real-WorldMedium

Ask the user for a password and print whether it meets a minimum length of 8 characters, using len() and >=.

Q23Real-WorldMedium

Ask the user for a number and print whether it's even, using %.

Q24Real-WorldMedium

Ask the user for a year and print whether it's divisible by 4.

Q25ComparisonMedium

Ask the user for a number and print whether it falls between 10 and 20 (inclusive), using a single chained comparison.

Q26LogicalMedium

Ask for the user's age and whether they have an ID (yes/no). Print is_eligible, True only if they're 18+ and have an ID.

Q27LogicalMedium

Ask whether the user is a member (yes/no) and their cart total. Print gets_discount, True if they're a member or their total exceeds 1000.

Q28MembershipMedium

Create shopping_list = ["milk", "bread", "eggs"]. Ask the user for an item and print whether it's in the list.

Q29DebuggingMedium

The following code is meant to check if a score equals a perfect score, but the comparison doesn't reliably work as intended. Find and fix the bug.

score = int(input("Enter your score: "))
target = 100
print("Perfect score:", score is target)
Q30PrecedenceMedium

Create is_admin = False and is_owner = True. Print the result of not is_admin and is_owner or False, and explain in a comment how not, and, and or are grouped.

Q31PrecedenceHard

Evaluate 2 + 3 * 4 ** 2 - 1 and print the result. Add a comment breaking down the exact order of operations.

Q32PrecedenceHard

Evaluate 5 + 3 > 2 * 3 and print the result. Explain in a comment why arithmetic operators run before the comparison.

Q33ComparisonHard

Print 5 > 3 > 1 and (5 > 3) > 1 on separate lines. They give different results — explain why in a comment.

Q34ComparisonHard

Print 0.1 + 0.2 == 0.3. It's not True — print two working alternatives that correctly check "close enough" equality for floats.

Q35IdentityHard

Create a = 256 and b = 256, then print a is b. Create c = 1000 and d = 1000, then print c is d. Explain the difference in a comment.

Q36Logical vs BitwiseHard

Create p = True and q = False. Print p and q alongside p & q, and p or q alongside p | q. They give the same results for booleans — explain in a comment what actually differs between them.

Q37MembershipHard

Create text = "hello world" and words = ["hello", "world", "python"]. Print whether "hello" is in each of them, showing that in works the same way across different sequence types.

Q38AssignmentHard

Create message = "Py" and use += to make it "Python". Separately, create border = "-" and use *= to repeat it 10 times. Print both.

Q39Compound ExpressionsHard

Use the walrus operator (:=) to assign 10 to n and print it in the same expression, then print n again on its own.

Q40Compound ExpressionsHard

Create allowed_scores = [90, 95, 100]. Ask the user for a score and print is_valid, True only if the score is in the list and greater than 90.

Q41Mini-ProjectMini-Project

Build a loan "Eligibility Checker". Ask for age, income, and credit_score. Print three individual boolean checks (age >= 21, income >= 30000, credit_score >= 700) and a combined all_criteria_met result.

Q42Mini-ProjectMini-Project

Build "Password Strength Flags". Ask for a password and print whether it's at least 8 characters, whether it contains no spaces, and whether both are true (is_strong).

Q43Mini-ProjectMini-Project

Build a "Shopping Cart Discount Engine". Ask for the cart total and membership status. A discount applies if the total is >= 1000 or the shopper is a member. Print a formatted summary.

Q44Mini-ProjectMini-Project

Build a "Number Property Reporter". Ask for a number and print whether it's even, positive, within the range 1–100, and a perfect square (compare number ** 0.5 to its int() version).

Q45Mini-ProjectMini-Project

Build "Access Control Flags". Given a fixed allowed_users list and a fixed correct password, ask for username, password, and whether the account is active, then print each check plus a combined access_granted.

Q46InterviewInterview

Demonstrate short-circuit evaluation: show that (x != 0) and (10 / x > 1) doesn't crash when x = 0, and that (y > 0) or (10 / 0 > 1) doesn't crash when y = 5. Explain why in a comment.

Q47InterviewInterview

Demonstrate one scenario where using is instead of == causes a bug, and one scenario where == works but is is the more correct/idiomatic choice.

Q48InterviewInterview

Ask for a number and print three flags: divisible by 3, divisible by 5, and divisible by both — using % and and.

Q49InterviewInterview

Given score = 85, print a single boolean is_valid_percentage that is True only if score is an int and falls between 0 and 100 inclusive, combining isinstance(), a chained comparison, and and in one expression.

Q50CapstoneInterview

Build an "Operator Mastery Report". Ask for two numbers a and b, then print every arithmetic operator (+ - * / // % **), every comparison operator (== != > < >= <=), and three logical combinations (a>0 and b>0, a>0 or b>0, not(a==b)) — all clearly labeled in one aligned report.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session