Skip to main content

Unit 3 · Decisions, Decisions · Lesson 25 of 57

Falsity

Decisions, decisions!

So far, your programs do the exact same thing every single time. Line 1, line 2, line 3, done.

Real programs make decisions. Is the password right? Is this user an admin? Did Alex delete the website again?

To make a decision, Python first has to ask a question. And every question it asks has one of two answers: True or False.

Remember booleans from Varying Variables? This is where they finally get to shine.

Asking questions

print(5 > 3)
print(5 < 3)
True
False

5 > 3 is a question: is 5 bigger than 3? Python works out the answer and teleports back True or False, the same way add(2, 3) teleports back 5.

Here are all the questions you can ask:

SymbolQuestion
==Are these equal?
!=Are these NOT equal?
>Is the left one bigger?
<Is the left one smaller?
>=Bigger or equal?
<=Smaller or equal?

= vs ==

This is the big one, so read it twice.

  • = stores. password = "amer123" puts "amer123" into password.
  • == asks. password == "amer123" asks "is password the same as amer123?" and gives back True or False.

One equals sign tells, two equals signs ask.

password = "amer123"
print(password == "amer123")
print(password == "Amer123")
True
False

Capitals count! To Python, amer123 and Amer123 are completely different strings.

Question

Answer it in the lesson and it is checked as soon as you send it. Create a free account to do this part.

Zain is setting up the Wi-Fi, and he wants to check a few things.

Print the answer to each of these questions, each on its own line:

  1. Is devices bigger than max_devices?
  2. Is network equal to "CyberAcad-WiFi"?
  3. Is password NOT equal to "amer123"?

Ask Python, don't just type True or False yourself!

Python exercise

Write the program in an editor next to the lesson, run it, and have it checked automatically. Create a free account to do this part.

Do this lesson for real

With a free account you get the terminals, challenges and checks that go with the lessons in Intro to Python, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.