Python conditionals — practice with a sign-up validator, tier discounts and a grade classifier (and the form that only showed you one error)
The week I started conditionals I signed up on a gym’s website. I typed a two-letter username and a short password, and the site said: “The username must have at least 3 characters”. I fixed it and sent it again. “The password must have at least 6 characters”. I fixed it. “The password must contain a digit”. Three attempts to find three errors the website knew about from the very first one. That night, doing the FP1 practice, I realised my validator did exactly the same, and why: everything was inside a single elif chain.
That’s the lesson running through this practice: an if/elif chain picks one path; several ifs in a row check several things. Knowing which one you need at each moment is half of programming with conditionals.
This is the practice for the Python conditionals theory. We’re going to write three complete, intermediate-level programs with if, elif, else, and, or and the ternary: a sign-up form validator, a customer tier discount system and a grade classifier with a menu. The data is fixed in variables instead of input(), so you can run each program and get exactly the same output as here; and the data is chosen to look like real data: a username that’s too short, an email with no dot, a customer one cent away from the next tier… Once it’s clear, swap each variable for an input() and you’ll have the interactive version.
Table of Contents
Before you start
Make sure you’re clear on:
- That in an
if/elif/elsechain only the block for the firstTrueruns. - How to combine conditions with
and,orandnot, and that0 <= grade <= 10checks a range. - That
input()always returns text (that’s why menu options are compared with"1"and not1). - The ternary operator:
"error" if n == 1 else "errors".
If any of these sounds shaky, review the theory before carrying on.
Create a conditionals_practice folder and one file per program (validator.py, discounts.py, classifier.py). In VS Code, run them with the run button (the triangle at the top right) or with python3 validator.py in the integrated terminal. That way you can change a value and run again in two seconds.
Program 1: sign-up form validator
Any website checks your details before creating an account. Our validator gets four pieces of data (username, age, password and email) and has to say what’s right and what’s wrong. What makes it tricky: we have to decide whether to stop at the first error or check them all, and the password has two requirements that depend on each other.
The idea
We start with the naive version, the gym website one: a single if/elif chain. Then we turn it into one independent if per field, with an errors counter that each failure increases. Inside the password field we do use elif, because there the two requirements are linked: if the password is too short, there’s no point also complaining that it lacks a digit.
Before coding, think about this for each check: are the cases mutually exclusive (one or the other) or independent (one, the other, both or neither)? Exclusive → elif. Independent → separate ifs.
The code
First, version 1, the single chain:
# Sign-up validator — version 1: a single if/elif chain
username = "Jo"
age = 20
password = "abc"
email = "sergio@sergiolearns.com"
print("=== USER SIGN-UP ===")
if len(username) < 3: # the first True condition...
print("Error: the username must have at least 3 characters")
elif age < 18: # ...cuts the chain: the rest is not checked
print("Error: you must be at least 18")
elif len(password) < 6:
print("Error: the password must have at least 6 characters")
elif "@" not in email or "." not in email:
print("Error: the email is not valid")
else: # only if NONE was True
print("Sign-up completed successfully")
With username "Jo" and password "abc" (two errors), the output is:
=== USER SIGN-UP === Error: the username must have at least 3 characters
Only one message. The first condition, len(username) < 3, is True (len("Jo") is 2), Python runs its block and leaves the chain. The short password is there, but nobody looks at it. That’s the correct behaviour of an elif… and exactly what we don’t want in a form.
Now version 2, with one if per field:
# Sign-up validator — version 2: one independent if per field
username = "Jo"
age = 20
password = "abc"
email = "sergio@sergiolearns.com"
errors = 0 # every failed check adds 1
print("=== USER SIGN-UP ===")
# 1. Username: at least 3 characters
if len(username) < 3:
print("✗ Username too short (minimum 3 characters)")
errors += 1
else:
print("✓ Username is valid")
# 2. Age: 18 or more (that is why < 18 and not <= 18)
if age < 18:
print("✗ You must be at least 18")
errors += 1
else:
print("✓ Age is valid")
# 3. Password: length first; the digit is only checked if the length is fine
if len(password) < 6:
print("✗ Password too short (minimum 6 characters)")
errors += 1
elif not any(c.isdigit() for c in password): # is any character a digit?
print("✗ The password needs at least one digit")
errors += 1
else:
print("✓ Password is valid")
# 4. Email: fails if the @ is missing OR the dot is missing
if "@" not in email or "." not in email:
print("✗ Email is not valid")
errors += 1
else:
print("✓ Email is valid")
# Summary: the ternary picks between "error" and "errors"
if errors == 0:
print("Sign-up completed")
else:
word = "error" if errors == 1 else "errors"
print(f"Sign-up failed: {errors} {word}")
Output
With the same data:
=== USER SIGN-UP === ✗ Username too short (minimum 3 characters) ✓ Age is valid ✗ Password too short (minimum 6 characters) ✓ Email is valid Sign-up failed: 2 errors
Now both failures come out at once. Check by hand: len("Jo") = 2 < 3 → no and errors goes to 1; 20 < 18 is False → yes; len("abc") = 3 < 6 → no and errors goes to 2 (the digit elif isn’t even looked at, because the length already failed); the email has an @ and a . → yes. Total: 2, and since it isn’t 1, the ternary picks “errors”.
I ran the same program with other data: username "laura_g", 19 years old, password "pythonfp" and email "laura@gmailcom". The real output:
=== USER SIGN-UP === ✓ Username is valid ✓ Age is valid ✗ The password needs at least one digit ✗ Email is not valid Sign-up failed: 2 errors
Here you can see the other password path: it has 8 characters, so it passes the length if and reaches the elif, where any(...) finds no digit. And the email has an @ but no ., so "." not in email is True and that’s enough for the or to give True.
The difference between the two versions is clear at a glance in this diagram:
Let’s take the hardest part, the password, again and on its own:
# 3. Password: length first; the digit is only checked if the length is fine
if len(password) < 6:
print("✗ Password too short (minimum 6 characters)")
errors += 1
elif not any(c.isdigit() for c in password): # is any character a digit?
print("✗ The password needs at least one digit")
errors += 1
else:
print("✓ Password is valid")
any(c.isdigit() for c in password) reads “is any character c of the password a digit?”. It goes through the password character by character and returns True as soon as it finds one. Inside it’s a small loop (you’ll see loops in depth in the next topic); for now, remember it answers yes or no. The not flips it: “there’s no digit at all”.
| Password | len(...) < 6 | Reaches the elif? | not any(digit) | Message |
|---|---|---|---|---|
"abc" | 3 < 6 → True | No | — | Too short |
"pythonfp" | 8 < 6 → False | Yes | True (no digits) | Needs a digit |
"fp1python" | 9 < 6 → False | Yes | False (the 1 is there) | Password is valid |
Questions you might ask
Why age < 18 and not age <= 18? Because at 18 you can already sign up. age < 18 only flags 17 and below. With <=, a user who just turned 18 would get an unfair error. Whenever you write a boundary, test it with the exact boundary value.
Why is the email check or and not and? Because the email is invalid if the @ is missing or the dot is missing: one missing piece is enough. With and, it would only fail when both were missing, and "laura@gmailcom" would pass as valid. It’s the “negative” version of “it must have an @ and a dot”.
Why a counter and not an all_ok boolean? A boolean would tell you whether there’s any error; the counter tells you how many, and the final message is more useful. Besides, errors == 0 is exactly the “all good” condition.
Why is the ternary only in the else? Because “error”/”errors” only makes sense when there are errors. If errors is 0, the program has already printed “Sign-up completed” and doesn’t need the word.
Is checking "@" in email enough to validate a real email? No: "@." would pass. Real websites use regular expressions or send a confirmation email. For FP1, this check is good practice for in, not in and or.
Writing the validator as an elif chain and thinking it “works” because it says “Sign-up completed” with correct data. The bug only shows when there are two or more errors at once. Always test with a case that has several.
Try it yourself
- Add a fifth field, “repeat password”, and flag an error if it doesn’t match the first one (
!=). - Change the final message so that, if there’s only one error, it says which one instead of “1 error” (hint: store the text of the last error in a variable).
Program 2: customer tier discount system
A shop classifies its customers by how much they spend per year: Basic, Silver, Gold and Platinum, each tier with its own discount. Members get an extra 5 % on any tier. The program works out the tier, the total discount, the savings and what they’d pay, and finishes with a message depending on the tier. The tricky part: getting the threshold order right, deciding what goes in the chain and what goes apart, and not failing right on the boundaries (exactly 500 €: Basic or Silver?).
The idea
This is the pattern you’ll use most in FP1: an if/elif/else chain that prints nothing and only assigns values to variables (tier and discount); the rest of the program works with those variables. The member bonus goes in a separate if, because it isn’t another tier: it adds on top of whichever tier there is. And the final message compares tier, not the money, so the thresholds aren’t repeated in two places.
Before coding, draw the brackets on a line and decide which side each boundary falls on. If the statement says “from 500 €”, 500 is Silver: that’s a >=.
The code
# Customer tier discount system
name = "Laura"
annual_spend = 2500.0
member_answer = "S" # as if it came from input(): a string
is_member = member_answer.lower() == "s" # "S" → "s" → True (accepts s and S)
# 1. Tier and base discount: highest first, the first threshold met wins
if annual_spend >= 5000:
tier = "Platinum"
discount = 20
elif annual_spend >= 2000: # here we already know annual_spend < 5000
tier = "Gold"
discount = 15
elif annual_spend >= 500:
tier = "Silver"
discount = 10
else:
tier = "Basic"
discount = 5
# 2. Member bonus: separate if, because it adds to ANY tier
if is_member:
extra_discount = 5
else:
extra_discount = 0
total_discount = discount + extra_discount
# 3. Sums
savings = annual_spend * total_discount / 100
would_pay = annual_spend - savings
print(f"--- Profile of {name} ---")
print(f"Annual spend: {annual_spend:.2f} €")
print(f"Tier: {tier} (base discount {discount} %)")
if is_member: # this line only shows for members
print(f"Member discount: +{extra_discount} %")
print(f"Total discount: {total_discount} %")
print(f"Savings: {savings:.2f} €")
print(f"Would pay: {would_pay:.2f} €")
# 4. Message from the tier already worked out (money comparisons are not repeated)
if tier == "Platinum":
print("⭐ Platinum: access to exclusive events")
elif tier == "Gold":
print("🥇 Gold: free shipping on every order")
elif tier == "Silver":
print("🥈 Silver: early access to sales")
else:
missing = 500 - annual_spend
print(f"ℹ️ You are {missing:.2f} € short of Silver")
Output
With Laura, who spends 2,500 € a year and is a member:
--- Profile of Laura --- Annual spend: 2500.00 € Tier: Gold (base discount 15 %) Member discount: +5 % Total discount: 20 % Savings: 500.00 € Would pay: 2000.00 € 🥇 Gold: free shipping on every order
Check by hand: 2500 >= 5000 is False; 2500 >= 2000 is True → Gold, 15 %. She’s a member → +5 %, 20 % in total. Savings: 2500 × 20 / 100 = 500. Would pay: 2500 − 500 = 2000. Everything adds up.
And now the boundaries, which is where programs fail. Pablo spends exactly 500 € and isn’t a member:
--- Profile of Pablo --- Annual spend: 500.00 € Tier: Silver (base discount 10 %) Total discount: 10 % Savings: 50.00 € Would pay: 450.00 € 🥈 Silver: early access to sales
With 500 €, 500 >= 500 is True: Silver. And if he spent one cent less, 499.99 €:
--- Profile of Pablo --- Annual spend: 499.99 € Tier: Basic (base discount 5 %) Total discount: 5 % Savings: 25.00 € Would pay: 474.99 € ℹ️ You are 0.01 € short of Silver
Here every condition is False and it goes into the else: Basic with 5 %. Look at the maths: 499.99 × 5 / 100 = 24.9995, which with two decimals (:.2f) rounds to 25.00; and 499.99 − 24.9995 = 474.9905, which becomes 474.99. That’s why amounts are printed with :.2f: with money you always want two decimals, and without formatting you’d see tails like 24.999499999999998. The “Member discount” line doesn’t appear either, because that print is inside an if is_member:.
The diagram places the three customers in their tiers:
Let’s look at the most curious line of the program:
Read it from right to left: member_answer.lower() turns "S" into "s", then == "s" compares and gives True, and that True is stored in is_member. A single comparison accepts “s” and “S”, and avoids the answer == "s" or "S" trap you saw in the theory.
| Step | Expression | Value |
|---|---|---|
| 1 | member_answer | "S" |
| 2 | member_answer.lower() | "s" |
| 3 | "s" == "s" | True |
| 4 | is_member | True |
Questions you might ask
Why do the thresholds go from highest to lowest? Because we use >=. If annual_spend >= 500 came first, Laura (2,500 €) would go in there and stay in Silver: the 9.2 bug from the theory, but with money. With >=, always from the most demanding condition to the least demanding one.
Why not elif annual_spend >= 2000 and annual_spend < 5000? Because if Python reaches that elif, it already knows the condition above (>= 5000) failed. The second half is guaranteed; writing it only adds a chance to get a number wrong.
Why isn’t the member bonus just another elif? Because it isn’t exclusive with the tiers: a Gold customer can be a member and so can a Basic one. If it were an elif in the chain, it would only apply when no tier matched. Independent → separate if.
Why does the final message compare tier and not the money? So the thresholds are written in a single place. If tomorrow Silver starts at 600 €, you change one line and the message still matches.
The boundary. “From 500 €” is >= 500, not > 500. With >, Pablo and his exact 500 € would stay in Basic. Always test the exact value of each threshold and the one just below it.
When an if/elif chain only assigns variables, line up the assignments like here (tier and discount in every branch). If a variable is missing from a branch, you spot it at a glance… and you avoid the NameError of using it later without having created it.
Try it yourself
- Add a Diamond tier from 10,000 € with 25 %. Where in the chain does it have to go?
- Make the member bonus depend on the tier: +5 % for Basic and Silver, +3 % for Gold and Platinum (hint: a ternary or an
ifwithor).
Program 3: grade classifier with a menu
The most complete of the three, and the one that uses this topic’s guiding example: FP1 grades. A menu offers three options (classify a grade, compare two grades and work out what you need in the exam) and the program does one thing or another depending on the option chosen. The tricky part: there are conditionals inside conditionals, impossible grades have to be ruled out before classifying, and option 3 has three outcomes depending on a calculation.
The idea
The outer structure is an if option == "1" / elif "2" / elif "3" / else chain: the options are mutually exclusive and the else catches anything invalid. Inside each option goes its own logic. In option 1, the first question is “is the grade possible?”; only if it is does it get classified. That way the grade chain never receives a 12 or a −3.
For option 3 we use an example grading rule, the same one as in the theory’s Python Tutor: final grade = 40 % coursework + 60 % exam, and you need at least a 4 in the exam. Solving for the exam, the grade you need to reach 5 is (5 − 0.4 × coursework) / 0.6.
Before coding, think about this: menu options would come from input(), and input() returns text. That’s why we compare with "1" and not 1. If you compare a string with a number, "1" == 1 is simply False, with no error, and the menu would never enter any option.
The code
# Grade classifier with a menu
option = "1" # what would be picked in the menu (input() returns text)
grade = 6.5 # data for option 1
grade1 = 6.5 # data for option 2
grade2 = 8.0
coursework_grade = 5.5 # data for option 3
print("=== GRADE CLASSIFIER ===")
print("1. Classify a grade")
print("2. Compare two grades")
print("3. What do I need in the exam?")
print(f"Chosen option: {option}")
if option == "1":
# Rule out the impossible first: the chain below only sees valid grades
if not 0 <= grade <= 10:
print("Error: the grade must be between 0 and 10")
else:
if grade >= 9:
grade_name = "Outstanding"
elif grade >= 7:
grade_name = "Very good"
elif grade >= 5:
grade_name = "Pass"
else:
grade_name = "Fail"
print(f"Grade {grade}: {grade_name}")
if grade < 5:
print(f"You are {5 - grade:.1f} points short of a pass")
else:
print(f"You have {grade - 5:.1f} points above a pass")
elif option == "2":
if grade1 > grade2:
print(f"Grade 1 ({grade1}) wins by {grade1 - grade2:.1f} points short")
elif grade2 > grade1:
print(f"Grade 2 ({grade2}) wins by {grade2 - grade1:.1f} points short")
else: # neither greater nor smaller: equal
print(f"Tie: both are {grade1}")
average = (grade1 + grade2) / 2
print(f"Average: {average:.2f} ({'Pass' if average >= 5 else 'Fail'})")
elif option == "3":
# Example rule: final = 40 % coursework + 60 % exam, and the exam needs a 4
needed = (5 - 0.4 * coursework_grade) / 0.6
if needed > 10:
print("Not even a 10 in the exam gets you to 5: time to resit the coursework")
elif needed <= 4:
print("The minimum 4 in the exam is enough to pass")
else:
print(f"You need at least {needed:.2f} in the exam")
else: # any other text
print("Invalid option: choose 1, 2 or 3")
Output
With option = "1" and a 6.5:
=== GRADE CLASSIFIER === 1. Classify a grade 2. Compare two grades 3. What do I need in the exam? Chosen option: 1 Grade 6.5: Pass You have 1.5 points above a pass
0 <= 6.5 <= 10 is True, so not turns it into False and it goes into the else. There, 6.5 >= 9 and 6.5 >= 7 fail and 6.5 >= 5 succeeds: Pass. And since 6.5 < 5 is False, it prints the points above a pass: 6.5 − 5 = 1.5.
To see the other branches I ran the same program changing only the first line. With option = "2" (grades 6.5 and 8.0):
=== GRADE CLASSIFIER === 1. Classify a grade 2. Compare two grades 3. What do I need in the exam? Chosen option: 2 Grade 2 (8.0) wins by 1.5 points Average: 7.25 (Pass)
6.5 > 8.0 is False; 8.0 > 6.5 is True → grade 2 wins by 8.0 − 6.5 = 1.5. Average: (6.5 + 8.0) / 2 = 7.25, and the ternary says “Pass” because 7.25 >= 5.
With option = "3" and 5.5 in coursework:
=== GRADE CLASSIFIER === 1. Classify a grade 2. Compare two grades 3. What do I need in the exam? Chosen option: 3 You need at least 4.67 in the exam
And with an option that doesn’t exist, option = "7":
=== GRADE CLASSIFIER === 1. Classify a grade 2. Compare two grades 3. What do I need in the exam? Chosen option: 7 Invalid option: choose 1, 2 or 3
None of the three comparisons is True, so the program falls into the final else. Without that else, an invalid option would print nothing and the user wouldn’t know what happened.
Option 3 deserves a zoom:
elif option == "3":
# Example rule: final = 40 % coursework + 60 % exam, and the exam needs a 4
needed = (5 - 0.4 * coursework_grade) / 0.6
if needed > 10:
print("Not even a 10 in the exam gets you to 5: time to resit the coursework")
elif needed <= 4:
print("The minimum 4 in the exam is enough to pass")
else:
print(f"You need at least {needed:.2f} in the exam")
The maths: 0.4 × 5.5 = 2.2; 5 − 2.2 = 2.8; 2.8 / 0.6 = 4.666…, which :.2f prints as 4.67. Then three mutually exclusive cases, and again order matters: first the impossible (more than 10), then what the minimum 4 already covers and, in the else, everything else.
| Coursework | Calculation | needed | Branch | Message |
|---|---|---|---|---|
| 5.5 | (5 − 2.2) / 0.6 | 4.67 | else | You need at least 4.67 |
| 9.5 | (5 − 3.8) / 0.6 | ≈ 2 (1.9999999999999996) | elif needed <= 4 | The minimum 4 is enough |
| 0 | (5 − 0) / 0.6 | 8.33 | else | You need at least 8.33 |
(The 5.5 row is the real output above; the other two are the calculations by hand so you can see which branch each case would go to.) The diagram marks the three zones:
Why does needed <= 4 say “the minimum 4 is enough”? Because even if the maths says a 2 would do, the rule still demands a 4 in the exam. That branch exists so nobody is told “you need 2.00” when a 2 would fail them for not reaching the minimum.
Questions you might ask
Why if not 0 <= grade <= 10 and not if grade < 0 or grade > 10? Both work (they’re equivalent by De Morgan’s laws). The first reads as “if the grade isn’t in the range”, which is exactly what we mean. What wouldn’t work is grade < 0 and grade > 10: no number is both below 0 and above 10, so it would never flag an error.
Why is there an if inside the else of option 1? Because “are you short of a pass or above it?” only makes sense with a valid grade. It’s nesting with a reason: the inner question depends on the outer one.
Why {5 - grade:.1f}? So that a subtraction like 5 − 4.3 (which gives 0.7000000000000002 on a computer) is printed as 0.7. The format only rounds when displaying; the variable’s value doesn’t change.
Why is the tie an else and not elif grade1 == grade2? Because if it’s neither greater nor smaller, it can only be equal. An elif with the condition written out would work too, but the else makes it clear there’s no fourth possible case.
What if the user types " 1" with a space? With input(), that happens more than you’d think. " 1" == "1" is False, so it would land in “Invalid option”. The fix is to clean the text when reading it: input(...).strip().
Comparing the option with a number (if option == 1:) when it comes from input(). It doesn’t raise an error: it’s just never equal, and the program always says “Invalid option”. If a menu “ignores” every option, check the types first.
Try it yourself
- Add an option 4 that says whether a grade is “with honours” (10) using
==, and check that option 7 still falls into theelse. - In option 3, check before calculating that
coursework_gradeis between 0 and 10, just like in option 1.
The pattern you’ll use most in FP1
If you keep just one thing from this practice, make it this: classify with an if/elif/else chain that only assigns, and use the variable afterwards. You’ve seen it in the discounts (tier, discount) and in the grades (grade_name). This is its general shape, with the grades example:
if grade >= 9: # most demanding threshold first (with >=)
category = "Outstanding"
elif grade >= 7: # here we already know grade < 9
category = "Very good"
elif grade >= 5:
category = "Pass"
else: # everything that didn't get in above
category = "Fail"
print(f"Category: {category}") # the variable is used AFTER the chain
It’s the same template for temperatures (cold, mild, hot), ages (child, teenager, adult), prices by bracket or battery levels. Three things that never fail: the else at the end so the variable always exists, the thresholds in order, and never repeating in an elif what the one above already guarantees.
Common mistakes in this practice
- Using an
elifchain for independent checks. The validator only reports the first failure. Independent → severalifs. - Thresholds in the wrong order. With
>=, highest first; otherwise the high branches can never be reached. - Failing on the exact boundary. “From 500” is
>= 500. Always test the boundary value and the one just below. andwhereorshould be (and vice versa). “The email is wrong if the@is missing or the dot is missing” needsor; withandalmost everything passes.- Comparing the menu option with a number.
input()returns text: compare with"1". - A variable that’s only created in some branches. If a branch doesn’t assign
discountand you use it later,NameError. Assign it in every branch or give it a value before the chain.
Watch it step by step in Python Tutor
On pythontutor.com you can watch the discount program run line by line, with every variable’s value at each moment. Choose Python 3 and paste this shorter version (without the profile prints):
annual_spend = 2500.0
is_member = True
if annual_spend >= 5000:
tier = "Platinum"
discount = 20
elif annual_spend >= 2000:
tier = "Gold"
discount = 15
elif annual_spend >= 500:
tier = "Silver"
discount = 10
else:
tier = "Basic"
discount = 5
if is_member:
discount = discount + 5
would_pay = annual_spend - annual_spend * discount / 100
print(tier, discount, would_pay)
At the end you should see:
Gold 20 2000.0
What to watch step by step:
- At the first comparison (
annual_spend >= 5000), the arrow doesn’t enter the Platinum block: it jumps straight to the nextelif. - At
elif annual_spend >= 2000, the arrow does go in:tier = "Gold"anddiscount = 15appear in the panel. Then it jumps over Silver and theelsewithout touching them. - At
if is_member:, watchdiscountgo from 15 to 20 in the panel: the same variable changes value, no new one is created. - When
would_payis calculated, check the maths in the panel:2500 − 2500 × 20 / 100 = 2000.0. Changeis_membertoFalseand run it again: you’ll see the member block skipped and the result becomes2125.0.
Summary and next step
- An
if/elif/elsechain picks a single path; severalifs in a row check several things. The sign-up validator needs the second. - With
>=, thresholds go from highest to lowest; when you reach anelif, everything above is alreadyFalseand doesn’t need re-checking. - The FP1 pattern: the chain only assigns (
tier,discount,grade_name) and the rest of the program uses those variables. - Boundaries are where programs fail: exactly 500 € is Silver, 499.99 € isn’t yet.
input()returns text: menu options are compared with"1", and.lower()solves the “s” or “S” problem.- First rule out impossible data (
if not 0 <= grade <= 10) and then classify what’s left.
Checklist: have you practised it?
- Have you run all three programs and checked the outputs?
- Can you explain why version 1 of the validator only shows one error?
- Have you tried the discounts with exactly 500 € and with 499.99 €?
- Can you say, without running it, what the classifier prints with
option = "3"and 9.5 in coursework? - Have you tried the “Try it yourself” tasks without looking at the theory?
- Have you swapped a value for an
input()and checked it still works?
If you answered yes to almost everything, you’re ready for the Python conditionals exercises, where I no longer give you the code. See you there! And if you want to review the basics, the conditionals theory and Python operators are still there; the next topic in the series is Python loops.
Next step: exercisesPython conditionals — solved exercises with movies, tax brackets, passwords and the number guessing game (and the or that let everybody in)Did this article help you? Here is how you can support SergioLearns →




What is an operating system — theory with your laptop on a study afternoon, a write() call and a CPU that never rests (and the three programs that weren’t running at the same time)