6 Making decisions with code
6 Making decisions with code
Master subtitle
Making decisions with code style
if statements
Branching
What if you get a free toaster for over
$100 and a free mug for under $100
deposit=input("How much would you like to
deposit? ")
if float(deposit) > 100 :
print("You get a free toaster!")
else:
print("Enjoy your mug!")
print("Have a nice day")
The code in the else statement is only
executed if the condition is NOT true
What will appear on the screen if we enter 50?
150? 100?
DEMO
Adding an else clause
You can use boolean variables to
remember if a condition is true or false
deposit= input("how much would you like to deposit? ")
if float(deposit) > 100 :
#Set the boolean variable freeToaster to True
freeToaster=True