# Chapter3.py # Relational Operators page 67 ## > < >= <= == etc... ## lower order a-z A-Z 0-9 spec higher order ### is bob > Bob False ### 9 > B True # Logical Operators page 69 ## and or not ## if you use a logical the variable to be tested HAS TO BE on both sides of the test, even if the variable name is the same ### age > 18 and age < 21 ### age > 18 or state = "FL" # lower(), upper() and title() page 71 ## changing case types ## only be called with string data type or char data type ## .lower() firstname.title() emailadd.lower() # if else statement page 73 ## if elif else ### if is the only required keyword ### else if to retest the False return keyword is elif (you can have multiple retests for the false) #### DRY Principle "Dont Repeat Yourself" repeat else if 3x think about 'is there a way to do this better' ### else is called when the final False is passed (only have 1 call to else) state = input("Enter your state: ") # data type string # florida FLOrida FloRida FLORIDA print(state) # florida lower case state = state.title() print(state) # Florida # Ask the user for there age, and we will use it MOSTLY as an integer. Print the age variable after the user enters it. Name the variable 'age'. # while loop page 85 # control variable "controls the loop" age = int( input("Enter your age: ") ) # MOSTLY print(age) choice = "yes" while age > 0 and age < 99: # if !TRUE break # run the code for the VALID age range if age < 18 and state == "Florida": # : specifies sub operator # tab indent or 4 nb spaces print("You can not rent a car.") # conditional return age < 18 and state =="Florida" if age >= 16: # nested if page 77 print(f"You need a parents signature to rent a car at {age} in {state}") elif age < 18 and state == "Iowa": # any state input NOT EQUAL to "Florida" print("You can rent a car in Iowa for a max of 5 days.") elif age < 18: print("You can rent a car with no restrictions.") # If you have to keep adding addition state tests, ask yourself, is there a better way to do this? match/loop/etc... # match keyword is available in Python 3.10 and above "switch/case" # for x in ys loop # re pattern matching # because of the while keyword age > 0 or age < 99 else: # anything that finally returns false print("Age and State are not limited when renting a car") choice = input("Do you want to check other ages and states: (yes/no): ") choice = choice.lower() print("Break from either INVALID AGE or user entering No in the loop") # EOF Chapter3.py