Conditionals & Control Flow

Lesson 01/15 – Go With The Flow

 
def clinic():
    print "You've just entered the clinic!"
    print "Do you take the door on the left or the right?"
    answer = raw_input("Type left or right and hit 'Enter'.").lower()
    if answer == "left" or answer == "l":
        print "This is the Verbal Abuse Room, you heap of parrot droppings!"
    elif answer == "right" or answer == "r":
        print "Of course this is the Argument Room, I've told you that already!"
    else:
        print "You didn't pick left or right! Try again."
        clinic()

clinic()

Lesson 02/15 – Compare Closely!

 
# Assign True or False as appropriate on the lines below!
bool_one = True

bool_two = True

bool_three = False

bool_four = False

bool_five = False

Lesson 03/15 – Compare… Closelier!

 
# Assign True or False as appropriate on the lines below!

bool_one = False

bool_two = True

bool_three = False

bool_four = True

bool_five = False

Lesson 04/15 – How the Tables Have Turned

 
# Create comparative statements as appropriate on the lines below!

# Make me true!
bool_one = 5 == 5

# Make me false!
bool_two = 4 == 5

# Make me true!
bool_three = 20 + 3 < 25

# Make me false!
bool_four = 23 - 13 == 20

# Make me true!
bool_five = (20 + 10) * 2 >= 60

Lesson 05/15 – To Be and/or Not to Be

 
"""
     Boolean Operators
---------------------------
True and True is True
True and False is False
False and True is False
False and False is False

True or True is True
True or False is True
False or True is True
False or False is False

Not True is False
Not False is True

"""

Lesson 06/15 – And

 
bool_one = False

bool_two = False

bool_three = False

bool_four = True

bool_five = True

Lesson 07/15 – Or

 
bool_one = True

bool_two = True

bool_three = False

bool_four = True

bool_five = False

Lesson 08/15 – Not

 
bool_one = False

bool_two = True

bool_three = True

bool_four = True

bool_five = False

Lesson 09/15 – This and That (or This, But Not That!)

 
bool_one = False

bool_two = True

bool_three = True

bool_four = True

bool_five = False

Lesson 10/15 – Mix ‘n’ Match

 
# Use boolean expressions as appropriate on the lines below!

# Make me false!
bool_one = not True

# Make me true!
bool_two = True or not True

# Make me false!
bool_three = False and False

# Make me true!
bool_four = True or not (True or False)

# Make me true!
bool_five = False or True

Lesson 11/15 – Conditional Statement Syntax

 
response = "Y"

answer = "Left"
if answer == "Left":
 print "This is the Verbal Abuse Room, you heap of parrot droppings!"
 
# Will the above print statement print to the console?
# Set response to 'Y' if you think so, and 'N' if you think not.

Lesson 12/15 – If You’re Having…

 
def using_control_once():
 if 0 == 0:
 return "Success #1"

def using_control_again():
 if 8 < 9:
 return "Success #2"

print using_control_once()
print using_control_again()

Lesson 13/15 – Else Problems, I Feel Bad for You, Son…

 
answer = "'Tis but a scratch!"

def black_knight():
 if answer == "'Tis but a scratch!":
 return True
 else: 
 return False # Make sure this returns False

def french_soldier():
 if answer == "Go away, or I shall taunt you a second time!":
 return True
 else: 
 return False # Make sure this returns False

Lesson 14/15 – I Got 99 Problems, But a Switch Ain’t One

 
def greater_less_equal_5(answer):
 if answer > 5:
 return 1
 elif answer < 5: 
 return -1
 else:
 return 0
 
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

Lesson 15/15 – The Big If

 
def the_flying_circus():
 if True and True:
 return True
 elif 9 != 9:
 return False
 else:
 return "Nothing"