Python · Python Fundamentals

Operators: Practice Questions

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

Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.

Q1ArithmeticEasy

Create a = 15 and b = 4, then print a + b.

Q2ArithmeticEasy

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

Q3ArithmeticEasy

Using a = 15 and b = 4, print a * b.

Q4ArithmeticEasyMust Do

Using a = 15 and b = 4, print a / b. Also print the type of the answer — regular division always gives a float, even when it divides evenly.

Q5ArithmeticEasyMust Do

Using a = 15 and b = 4, print a // b. This is floor division: it divides and then throws away anything after the decimal point.

Q6ArithmeticEasyMust Do

Using a = 15 and b = 4, print a % b. The % operator gives the remainder left over after dividing.

Q7ArithmeticEasy

Create base = 2 and exponent = 10, then print base ** exponent (2 to the power of 10).

Q8ArithmeticEasy

Create temperature = 12 and print its negative using the unary minus operator, then print the negative of -5 to show that two minuses cancel out.

Q9ArithmeticEasy

Print 7 / 2, 7 // 2 and 7 % 2 on three lines, each with a label, so you can see how the three division operators differ on the same pair of numbers.

Q10AssignmentEasyMust Do

Create x = 10, add 5 using +=, then print x.

Q11AssignmentEasy

Create x = 50, subtract 20 using -=, then print x.

Q12AssignmentEasy

Create x = 6, triple it using *=, then print x.

Q13AssignmentEasy

Create x = 20, divide it by 4 using /=, then print x and its type. Note that /= always leaves a float behind.

Q14AssignmentEasy

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

Q15ComparisonEasyMust Do

Create a = 5 and b = 8, then print a == b and a != b. Note that == (compare) is a completely different operator from = (assign).

Q16ComparisonEasy

Create a = 7 and b = 3, then print a > b and a < b.

Q17ComparisonEasy

Create a = 7 and b = 7, then print a >= b and a <= b. Both are True — these operators accept "equal" as well.

Q18ComparisonEasy

Create number = 15 and check whether it sits between 10 and 20 inclusive, using a single chained comparison rather than two separate checks.

Q19LogicalEasyMust Do

Create is_sunny = True and is_weekend = False. Print is_sunny and is_weekend. and is True only when both sides are True.

Q20LogicalEasy

Using the same two variables, print is_sunny or is_weekend. or is True when at least one side is True.

Q21LogicalEasy

Print not is_sunny and not is_weekend. not simply flips a boolean to its opposite.

Q22MembershipEasyMust Do

Create word = "python" and print whether the letter "y" appears in it, using the in operator.

Q23MembershipEasy

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

Q24MembershipEasy

Create sentence = "the quick brown fox" and print whether the whole word "brown" appears inside it.

Q25IdentityEasyMust Do

Create value = None and print value is None and value is not None. is asks "are these the same object?" rather than "do these look equal?".

Q26PrecedenceEasyMust Do

Print 10 + 2 * 3 and explain the result in a comment. Multiplication is done before addition.

Q27PrecedenceEasy

Print (10 + 2) * 3 and compare it with the previous answer. Brackets force Python to do the addition first.

Q28PrecedenceMedium

Print 2 ** 3 ** 2. The answer is not 64 — explain why in a comment.

Q29PrecedenceMedium

Print -2 ** 2 and (-2) ** 2. They give different answers — explain why.

Q30PrecedenceMediumMust Do

Print 5 + 3 > 2 * 3 and explain in a comment why the arithmetic runs before the comparison.

Q31PrecedenceMedium

Create is_admin = False and is_owner = True. Print not is_admin and is_owner and explain how not, and and or are ranked.

Q32ComparisonMedium

Print 5 > 3 > 1 and (5 > 3) > 1 on separate lines. They differ — explain why.

Q33ArithmeticMediumMust Do

Create number = 34 and print whether it is even, by testing whether the remainder after dividing by 2 equals zero.

Q34ArithmeticMedium

Create number = 5847 and print its last digit using %.

Q35ArithmeticMedium

Using number = 5847, print its tens digit by combining // and %.

Q36ArithmeticMedium

Print the square root of 144 using the power operator with an exponent of 0.5.

Q37AssignmentMedium

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

Q38ComparisonMedium

Print "apple" < "banana" and "Zebra" < "apple". Explain in a comment how Python compares text.

Q39ComparisonMediumMust Do

Print 5 == "5" and 5 == 5.0. One is False and one is True — explain the difference.

Q40Data TypesMedium

Print True + True, True * 5 and False + 10. Explain why booleans behave like numbers.

Q41LogicalMedium

Given has_email = True, has_phone = False and has_address = True, print how many contact details are present by adding the booleans together.

Q42MembershipMedium

Ask the user for an email address and print whether it contains an @ sign and whether it contains a . — as two separate booleans.

Q43IdentityMedium

Create value = None and print both value is None and value == None. Explain which one you should write and why.

Q44IdentityMedium

Create x = 1000 and y = int("1000"). Print x == y and x is y, and explain why they differ.

Q45ArithmeticMedium

Print abs(-15) and abs(15). abs() gives the distance from zero, so it strips any minus sign.

Q46ArithmeticMedium

Print round(3.14159, 2) and round(3.14159). Passing a second number tells round() how many decimal places to keep.

Q47ComparisonMedium

Given price_a = 250 and price_b = 180, print the cheaper and the dearer price using min() and max().

Q48Compound ExpressionsMediumMust Do

Given price = 200 and tax_percent = 18, work out the final price in a single expression and print it to 2 decimal places.

Q49LogicalMediumMust Do

Print the result of "" or "guest" and "Asha" or "guest". or does not return True/False here — explain what it actually returns.

Q50Compound ExpressionsMedium

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

Q51Real-WorldMediumMust Do

Ask the user for a number and print whether it is even.

Q52Real-WorldMediumMust Do

Ask for the user's age and print is_teen, which is True only when the age is from 13 to 19 inclusive.

Q53Real-WorldMedium

Ask for a cart total and print free_shipping, which is True when the total is over 500.

Q54Real-WorldMedium

Ask for a password and print whether it is at least 8 characters long.

Q55Real-WorldMedium

Ask for a year and print whether it divides evenly by 4.

Q56Real-WorldMedium

Ask for a mark out of 100 and print whether it is a valid percentage, using one chained comparison.

Q57LogicalMediumMust Do

Ask for the user's age and whether they hold an ID (yes/no). Print is_eligible, True only when they are 18 or over and hold an ID.

Q58LogicalMedium

Ask whether the shopper is a member (yes/no) and for their cart total. Print gets_discount, True if they are a member or the total is above 1000.

Q59Real-WorldMedium

Ask for a number and print three booleans: divisible by 3, divisible by 5, and divisible by both.

Q60Real-WorldMedium

Ask for a number and print whether it is a perfect square, by comparing its square root to the whole-number version of that root.

Q61Real-WorldMedium

Ask for a number and print three separate booleans saying whether it is positive, negative, or exactly zero.

Q62Real-WorldMediumMust Do

Ask for a duration in total seconds and print it broken into hours, minutes and seconds using // and %.

Q63Real-WorldMedium

Ask for a bill total and a number of people. Print how much each person pays as a whole number of rupees, and how many rupees are left over, using // and %.

Q64Real-WorldMedium

Two shops sell rice. Ask for pack A's price and weight, and pack B's price and weight. Print each price-per-kg, and a boolean saying whether A is the better deal.

Q65Real-WorldMedium

Ask for a password and print whether it contains no spaces and is at least 8 characters, as a single combined boolean.

Q66Real-WorldMedium

Ask for the three angles of a triangle and print whether they form a valid triangle (they must add up to exactly 180 and each must be above 0).

Q67Real-WorldMedium

Ask for a username and print whether it is a valid length (3 to 15 characters) and contains no spaces.

Q68Real-WorldMedium

Ask for a temperature in Celsius and print two booleans: whether water would freeze at it, and whether water would boil at it.

Q69Real-WorldMedium

Ask for an amount in rupees and print how many 500, 100 and 10 notes are needed, largest first, using // and %.

Q70Compound ExpressionsMediumMust Do

Ask for a number and print a single boolean that is True only when the number is even, positive, and below 100 — combining three checks with and.

Q71ComparisonHardMust Do

Print 0.1 + 0.2 == 0.3. It is not True. Show two reliable ways to compare floats instead.

Q72ArithmeticHard

Print 7 // 2 and -7 // 2. The second is -4, not -3 — explain why.

Q73ArithmeticHard

Print 7 % 3 and -7 % 3. In Python the second is 2, which surprises people coming from other languages. Explain.

Q74IdentityHard

Create a = 256 and b = 256, print a is b. Then create c = int("257") and d = int("257"), and print c is d. Explain the difference.

Q75IdentityHard

Create a = "hello" and b = "hello", then print a is b. Explain the result and why you should not build code around it.

Q76Logical vs BitwiseHard

Create p = True and q = False. Print p and q next to p & q, and p or q next to p | q. They match here — explain what genuinely differs.

Q77BitwiseHard

Print 12 & 10, 12 | 10 and 12 ^ 10, showing each number in binary alongside the result so the bit-by-bit logic is visible.

Q78BitwiseHard

Print 5 << 1 and 5 >> 1. Explain in a comment what shifting left and right does to a number's value.

Q79LogicalHardMust Do

Show that and short-circuits: with x = 0, prove that x != 0 and 10 / x > 1 does not crash, even though dividing by x would.

Q80LogicalHard

Show that or short-circuits too: with y = 5, prove that y > 0 or 10 / 0 > 1 does not crash.

Q81PrecedenceHard

Print 2 + 3 * 4 ** 2 - 1 and break the full order of operations down in a comment.

Q82AssignmentHard

Create x = 5, print id(x), then run x += 1 and print id(x) again. The id changes — explain what that reveals about integers.

Q83ComparisonHard

Using the walrus operator, prove that in a chained comparison like a < b < c, the middle value is evaluated only once.

Q84MembershipHard

Given text = "the cat sat", print "cat" in text and "ca t" in text. Explain what in is really matching for strings.

Q85DebuggingHardMust Do

This is meant to check for a perfect score but is unreliable. Find and fix the bug.

score = int(input("Enter your score: "))
target = 1000
print("Perfect score:", score is target)
Q86Mini-ProjectMini-Project

Build a Loan Eligibility Checker. Ask for age, monthly income and credit score. Print each of the three checks (age 21+, income 30000+, credit score 700+) and a combined approval result.

Q87Mini-ProjectMini-ProjectMust Do

Build a Password Strength Report. Ask for a password and print four flags: at least 8 characters, no spaces, contains a digit-friendly length under 64, and an overall verdict. Also print how many of the checks passed, by adding the booleans.

Q88Mini-ProjectMini-Project

Build a Cart Discount Engine. Ask for the cart total and membership status. A discount applies when the total reaches 1000 or the shopper is a member. Print an aligned summary including the discounted total (10% off when it applies).

Q89Mini-ProjectMini-ProjectMust Do

Build a Number Property Reporter. Ask for a number and print whether it is even, positive, within 1–100, and a perfect square.

Q90Mini-ProjectMini-Project

Build an Access Control Report. Ask for a username, a password and whether the account is active. Access needs the username to match "admin", the password to match "secret123", and the account to be active. Print every check and the final decision.

Q91Mini-ProjectMini-Project

Build a Digit Splitter. Ask for a three-digit number and print its hundreds, tens and units digits separately, plus their sum — using only // and %.

Q92Mini-ProjectMini-Project

Build a Time Converter. Ask for a number of minutes and print it as days, hours and minutes.

Q93Mini-ProjectMini-Project

Build a Bit Permission Checker. Using READ = 4, WRITE = 2, EXECUTE = 1, ask the user for a permission number (0–7) and print whether each individual permission is switched on, using &.

Q94Mini-ProjectMini-Project

Build a Shape Validity Checker. Ask for three side lengths and print whether they can form a triangle. Three sides work only when every pair added together is longer than the remaining side.

Q95Mini-ProjectMini-Project

Build a Precedence Demonstrator. For the fixed expression 2 + 3 * 4 ** 2 - 1, print the fully bracketed version, each intermediate step, and confirm both forms give the same answer.

Q96InterviewInterview

Explain and demonstrate short-circuit evaluation in both directions, and give one practical reason it matters.

Q97InterviewInterview

Show one case where is instead of == creates a genuine bug, and one case where is is the correct choice.

Q98InterviewInterview

Given score = 85, print a single boolean that is True only when score is genuinely an int and falls between 0 and 100 — in one expression.

Q99InterviewInterview

Ask for a number and print the three FizzBuzz conditions as booleans — divisible by 3, divisible by 5, divisible by 15 — without using a single if.

Q100CapstoneInterviewMust Do

Build an Operator Mastery Report. Ask for two numbers and print, in one aligned report: every arithmetic operator, every comparison operator, three logical combinations, and the bitwise operators applied to their whole-number versions.

Still stuck on something?

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

Book a Free Session