Title: Layout 3
Course: CPS 120: Introduction to Computer Science ~ Master (Aug/2015) OLD > Section: Learning Units

✓ Layout 3 syntax – test whether to execute one of several blocks:

if <condition>:
<block>
elif <condition>:
<block>
else:
<block>

The italicized part in orange can be repeated as many times as is needed.

✓ Layout 3 example:

if option == 1:
print ("Option 1 selected.")
elif option == 2:
print ("Option 2 selected.")
elif option == 3:
print ("Option 3 selected.")
elif option == 4:
print ("Option 4 selected.")
else:
print ("Invalid option selected.")