if's - selection structures
- Michael Tomaino
- Dec 15, 2016
- 1 min read
The if structure explains the processing in the following:
Input > Processing > Output
The traditional program flow.
Simple
if this then that
decisions
Syntax:
if this :
Do that
Example:
if x < 9:
print(“x is less than 9.”)
Making it useful
Ask about something you don’t know - user input:
age=input(“What is your age?”)
age=int(age)
if age>=21:
print(“Please drink responsibly.”);
print(“If you’re drinking, don’t drive.”);
print(“Have a great day!”)
It’s not: “do this or do that” - we will cover those soon
It’s: “do this or don’t do this”
But it’s best to say: “if this then do that”
which implies: “if not this, then don’t do that”





Comments