Python L3 Selection
Python L3 Selection
Python L3 Selection
programs
Introduction to Python
Learning objectives
• Use selection statements if, else and elif in a
program
• Learn how to use different comparison operators
• Use indentation correctly to define a block of code
Introduction to Python
Selection
Indentation!
• Python requires indentation as part of the syntax
• Indentation signifies the start and end of a block of
code
• Programs will not run without correct indentation
if password == "abcd1234":
print("Access Granted")
else:
print("Access Denied")
Using an IF statement
• An IF Statement uses Selection
• IF forces a decision
• If condition Then do this Else do that
IF syntax
age = int(input("Enter age: "))
if age >= 18:
print ("Adult")
else:
print ("Child")
Introduction to Python
Selection
Comparison operators
Write a program
• Write a simple program that might be used inside a
police speed camera
The Requirements are:
– It must accept the driver’s
speed
– IF the speed is over 70mph, a
message “Issue Fine” should
appear on the speed gun
– Otherwise it should display
“No Action”
Introduction to Python
Selection