An if statement allows a program to make decisions based on certain conditions. It evaluates whether a condition is true or false, and if true, executes specific code.
In the real world, we use if statements to handle decisions like checking if a password is correct, verifying if a user is old enough to access certain content, or determining if an online store has items in stock before processing an order.
An If Statement is something we call a conditional
It checks for a specific condition to be true or false
If statements in Python will evaluate to 1 = True or 0 = False
Remember, this will execute it's code ONLY if the condition is True
There is also an else part, which is executed when the condition is False
This is just another name for a conditional Test
Boolean Value: (Pay Attention to Capitalization)
True
False
EQUALS =
Assigns a value
This sets something equal to something else
Example: x = 13
NOT EQUAL TO !=
Not Equal To
Example: x != 4
EQUALITY ==
Checks to see if something is equal
This is used for comparison
Example: if (x == 13)
This checks to see if x is equal to the value 13!
Dr. Heinz Doofenshmirtz has built his newest machine: The YES or NO-inator™ (It ONLY speaks in Booleans!)
He types in comparisons — and the machine decides whether they’re TRUE ✅ or FALSE ❌.
These exist just like in math class
Just be careful how you type them in!
TRY THIS JUST TO GET COMFORTABLE WRITING SOME OF THESE THINGS!!!
Bluey wants to share snacks with her friends, but she needs to make sure everyone gets the right number of snacks.
Instructions:
Ask the user how many snacks Bluey has
Ask the user how many friends Bluey has
If Bluey has enough snacks, tell the user, otherwise, let them know they need to get more!
Concepts Being Checked:
user input
number input
print statements
basic conditionals
Bluey has started a secret club and only allows her friends to enter if they know the correct password. Use conditionals to check if the password is correct and let the friend know if they can enter.
Instructions:
Create a variable containing Bluey's Secret Password. The user does NOT Enter this one
Ask the user for the secret password
If the user enters the correct password, let them in. If not, tell them they don't have the correct password!
Concepts Being Checked:
user input using strings
print statements
basic conditionals (= vs equality)
string formatting
Phineas & Ferb want to build something epic before dinner. You’ll write a program that:
lets the user choose a project from a numbered menu,
does a small calculation to compare available materials vs required,
runs a few boolean checks with if/else to decide if they can start today.
Your program must:
Print the menu and ask for a number (1–3).
Ask how many build-units the boys currently have (integer).
Based on the chosen project, set a required_units (120, 80, or 60).
Do a calculation for the gap/difference and use comparisons:
If available >= required_units → print a green-light message.
Else → print a shortfall message that shows how many more are needed
Keep these as simple if/else blocks (no need for and/or yet). Print a brief line for each check.
After Part 1, run these separate checks (each with its own if/else):
Noise check (ask 0–10):
noise <= 7 → “Noise level OK.”
otherwise → “Too loud—Buford’s already complaining.”
Permit check (ask 1 for Yes, 0 for No):
permit == 1 → “Permit approved by Mom.”
else → “No permit—Candace is texting Mom right now.”
Weather temperature check (ask temp °F):
If project was Backyard Beach: temp >= 70 → “Beach weather approved!”, else “Too chilly for sandcastles.”
For other projects: temp >= 50 → “Weather is workable.” else “Too cold for outdoor construction.”
At the beginning of the program:
Prompt the user to enter 3 tools and add those tools to the "toolbox" (list)
Once the project is selected:
Ask the user to select a tool from the tool box
Have a random tool picked from the list
If those 2 tools match, give them a fun message telling them they have the right tool for the job, and get a cool power-up!
Otherwise, tell them the job will take longer than they thought!
Here's Some Sample Output from the program you might see for this bonus section!!!
If there's a match in your toolbox...
If there's NOT a match in your toolbox...