# Chapter3.py # relational operators page 67 == >= <= ... # logical operators page 69 and or not ## IF you are going to use a logical operator you MUST define the variable name on BOTH sides of the operation ### age > 21 and state == "Florida" or vipStatus == True ### age > 18 and age < 21 # if statements page 72 if elif else ## elif -> else if age = int( input("Enter your age: ") ) # age ''' page 77 define your code statement age > 0 and age < 16 nothing if age >= 16 and age < 18 drive elif age >= 18 and age < 21 drive and vote elif age >= 21 and age < 72 drive, vote and drink elif age > 72 and age < 120 drive, vote, drink and retire elif else invalid age ''' # DRY Dont Repeat Yourself Principle # https://en.wikipedia.org/wiki/Don%27t_repeat_yourself # Rule of three # https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) # testing variables -> in the Level 2 these will end up being attrs beginAge = 0 drivingAge = 16 drivingText = 'drive' votingAge = 18 votingText = 'vote' drinkAge = 21 drinkingText = 'drink' retirementAge = 72 retirmentText = 'retire' endAge = 120 below16string = f'You are to young to {drivingText}, {votingText}, {drinkingText} or {retirmentText}.' if age > beginAge and age < drivingAge: # sub operation for the if line 25 print(below16string) elif age >= drivingAge and age < votingAge: print("You can drive, but not vote, drink or retire.") elif age >= votingAge and age < drinkAge: print("You can drive and vote, but not drink or retire.") elif age >= drinkAge and age < retirementAge: print("You can drive, vote and drink, but not retire.") elif age >= retirementAge and age < endAge: # over 72 < 120 print("You can drive, vote, drink and retire.") # age >= 72 and age < 120 # nested if statement page 76 if age > 86: print("You must take your driving test annually.") # If you do not need the False part (elif or else) then dont use it # True or Not True if age != 20 else: # optional keyword for False return print("Invalid age.") # EOF Chapter3.py