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.
Create a = 15 and b = 4, then print a + b.
Using the same a = 15 and b = 4, print a - b.
Using a = 15 and b = 4, print a * b.
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.
Using a = 15 and b = 4, print a // b. This is floor division: it divides and then throws away anything after the decimal point.
Using a = 15 and b = 4, print a % b. The % operator gives the remainder left over after dividing.
Create base = 2 and exponent = 10, then print base ** exponent (2 to the power of 10).
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.
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.
Create x = 10, add 5 using +=, then print x.
Create x = 50, subtract 20 using -=, then print x.
Create x = 6, triple it using *=, then print x.
Create x = 20, divide it by 4 using /=, then print x and its type. Note that /= always leaves a float behind.
Start with value = 17. Apply //= 3, then **= 2, then %= 5, printing value after each step.
Create a = 5 and b = 8, then print a == b and a != b. Note that == (compare) is a completely different operator from = (assign).
Create a = 7 and b = 3, then print a > b and a < b.
Create a = 7 and b = 7, then print a >= b and a <= b. Both are True — these operators accept "equal" as well.
Create number = 15 and check whether it sits between 10 and 20 inclusive, using a single chained comparison rather than two separate checks.
Create is_sunny = True and is_weekend = False. Print is_sunny and is_weekend. and is True only when both sides are True.
Using the same two variables, print is_sunny or is_weekend. or is True when at least one side is True.
Print not is_sunny and not is_weekend. not simply flips a boolean to its opposite.
Create word = "python" and print whether the letter "y" appears in it, using the in operator.
Using the same word = "python", print whether "z" is not in it, using not in.
Create sentence = "the quick brown fox" and print whether the whole word "brown" appears inside it.
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?".
Print 10 + 2 * 3 and explain the result in a comment. Multiplication is done before addition.
Print (10 + 2) * 3 and compare it with the previous answer. Brackets force Python to do the addition first.
Print 2 ** 3 ** 2. The answer is not 64 — explain why in a comment.
Print -2 ** 2 and (-2) ** 2. They give different answers — explain why.
Print 5 + 3 > 2 * 3 and explain in a comment why the arithmetic runs before the comparison.
Create is_admin = False and is_owner = True. Print not is_admin and is_owner and explain how not, and and or are ranked.
Print 5 > 3 > 1 and (5 > 3) > 1 on separate lines. They differ — explain why.
Create number = 34 and print whether it is even, by testing whether the remainder after dividing by 2 equals zero.
Create number = 5847 and print its last digit using %.
Using number = 5847, print its tens digit by combining // and %.
Print the square root of 144 using the power operator with an exponent of 0.5.
Create message = "Py" and use += to turn it into "Python". Separately create border = "-" and use *= to repeat it 10 times. Print both.
Print "apple" < "banana" and "Zebra" < "apple". Explain in a comment how Python compares text.
Print 5 == "5" and 5 == 5.0. One is False and one is True — explain the difference.
Print True + True, True * 5 and False + 10. Explain why booleans behave like numbers.
Given has_email = True, has_phone = False and has_address = True, print how many contact details are present by adding the booleans together.
Ask the user for an email address and print whether it contains an @ sign and whether it contains a . — as two separate booleans.
Create value = None and print both value is None and value == None. Explain which one you should write and why.
Create x = 1000 and y = int("1000"). Print x == y and x is y, and explain why they differ.
Print abs(-15) and abs(15). abs() gives the distance from zero, so it strips any minus sign.
Print round(3.14159, 2) and round(3.14159). Passing a second number tells round() how many decimal places to keep.
Given price_a = 250 and price_b = 180, print the cheaper and the dearer price using min() and max().
Given price = 200 and tax_percent = 18, work out the final price in a single expression and print it to 2 decimal places.
Print the result of "" or "guest" and "Asha" or "guest". or does not return True/False here — explain what it actually returns.
Use the walrus operator (:=) to assign 10 to n and print it in the same expression, then print n again on its own line.
Ask the user for a number and print whether it is even.
Ask for the user's age and print is_teen, which is True only when the age is from 13 to 19 inclusive.
Ask for a cart total and print free_shipping, which is True when the total is over 500.
Ask for a password and print whether it is at least 8 characters long.
Ask for a year and print whether it divides evenly by 4.
Ask for a mark out of 100 and print whether it is a valid percentage, using one chained comparison.
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.
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.
Ask for a number and print three booleans: divisible by 3, divisible by 5, and divisible by both.
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.
Ask for a number and print three separate booleans saying whether it is positive, negative, or exactly zero.
Ask for a duration in total seconds and print it broken into hours, minutes and seconds using // and %.
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 %.
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.
Ask for a password and print whether it contains no spaces and is at least 8 characters, as a single combined boolean.
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).
Ask for a username and print whether it is a valid length (3 to 15 characters) and contains no spaces.
Ask for a temperature in Celsius and print two booleans: whether water would freeze at it, and whether water would boil at it.
Ask for an amount in rupees and print how many 500, 100 and 10 notes are needed, largest first, using // and %.
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.
Print 0.1 + 0.2 == 0.3. It is not True. Show two reliable ways to compare floats instead.
Print 7 // 2 and -7 // 2. The second is -4, not -3 — explain why.
Print 7 % 3 and -7 % 3. In Python the second is 2, which surprises people coming from other languages. Explain.
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.
Create a = "hello" and b = "hello", then print a is b. Explain the result and why you should not build code around it.
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.
Print 12 & 10, 12 | 10 and 12 ^ 10, showing each number in binary alongside the result so the bit-by-bit logic is visible.
Print 5 << 1 and 5 >> 1. Explain in a comment what shifting left and right does to a number's value.
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.
Show that or short-circuits too: with y = 5, prove that y > 0 or 10 / 0 > 1 does not crash.
Print 2 + 3 * 4 ** 2 - 1 and break the full order of operations down in a comment.
Create x = 5, print id(x), then run x += 1 and print id(x) again. The id changes — explain what that reveals about integers.
Using the walrus operator, prove that in a chained comparison like a < b < c, the middle value is evaluated only once.
Given text = "the cat sat", print "cat" in text and "ca t" in text. Explain what in is really matching for strings.
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)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.
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.
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).
Build a Number Property Reporter. Ask for a number and print whether it is even, positive, within 1–100, and a perfect square.
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.
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 %.
Build a Time Converter. Ask for a number of minutes and print it as days, hours and minutes.
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 &.
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.
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.
Explain and demonstrate short-circuit evaluation in both directions, and give one practical reason it matters.
Show one case where is instead of == creates a genuine bug, and one case where is is the correct choice.
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.
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.
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