7-1
car = input("What kind of car would you like to lease? \n")
print("Let me see if I can find you a " + car)
7-2
user_num = input("How many people would like to have dinner?\n")
if int(user_num) > 8:
print("There is no vacant tables.")
else:
print("Here is a vacant table.")
7-3
num = input("Please input a number.\n")
if int(num) % 10:
print("It is not divisible by 10.")
else:
print("It is divisible by 10.")
7-4
while True:
ingredient = input('Please input an ingredient of pizza, or input "quit".\n')
if(ingredient == 'quit'):
break
else:
print("I would add " + ingredient +" to the pizza.")
7-5
while True:
age = input('How old are you?\n')
if int(age) < 3:
print("Free.")
elif int(age) > 12:
print("15 dollars, please.")
else:
print("10 dollars, please.")
7-6
# use condition testing
age = input('How old are you?\n')
while age != "quit":
if int(age) < 3:
print("Free.")
elif int(age) > 12:
print("15 dollars, please.")
elif int(age) >= 3 and int(age) <= 12:
print("10 dollars, please.")
age = input('How old are you?\n')
# use variable "active"
active = 1
while active:
age = input('How old are you?\n')
if age == "quit":
active = 0
else:
if(int(age) < 3):
print("Free.")
elif(int(age) > 12):
print("15 dollars, please.")
else:
print("10 dollars, please.")
# use "break" statement
active = 1
while active:
age = input('How old are you?\n')
if age == "quit":
break
if(int(age) < 3):
print("Free.")
elif(int(age) > 12):
print("15 dollars, please.")
else:
print("10 dollars, please.")
7-7
while True:
print("Gosick_Geass_Gate")
7-8
sandwich_orders = ['pepperoni', 'durian', 'bacon']
finished_sandwiches = []
for order in sandwich_orders:
print("I made your " + order +" sandwich. ")
finished_sandwiches.append(order)
print(finished_sandwiches)
7-9
sandwich_orders = ['pepperoni', 'pastrami', 'durian', 'pastrami','bacon', 'pastrami']
print("Pastrami has sold out. ")
finished_sandwiches = []
for order in sandwich_orders:
if order == 'pastrami':
continue
print("I made your " + order +" sandwich. ")
finished_sandwiches.append(order)
print(finished_sandwiches)
7-10
places = []
while True:
place = input("If you could visit one place in the world, where would you go?\n")
if place == "quit":
break
places.append(place)
for place in places:
print(place)