第七章 用户输入和while循环
7-1 汽车租赁
car = input("Which car do you want to buy?")
print ("Let me see if I can fond you a " + car)
7-2 餐馆定位
number = input("How many people will have the meal? ")
number = int(number)
if number > 8:
print ("There are no available table for having meal")
7-3 10的整数倍
num = input("Please input a number: ")
num = int(num)
if num % 10 == 0:
print ("The number is a multiplier of ten")
else:
print ("The number is not a multiplier of ten")
7-4 比萨配料
while True:
ingredient = input("Please input a pizza ingredient: ")
if ingredient == "quit":
break;
print ("We will add the ingredient to your pizza")
7-5 电影票
while True:
age = input("What is your age? ")
age = int(age)
if age <= 3:
print ("Free")
elif age <=12:
print ("10 dollars")
else:
print ("15 dollars")
7-7 无限循环
print ("It is an infinite loop")
while True:
number = input("Please input a number you like: ")
print ("Your number is " + number)
7-8 熟食店
sandwish_orders = ["A_sandwish", "B_sandwish", "C_sandwish", "D_sandwish"]
finished_sandwish = []
while sandwish_orders:
print ("I made your " + sandwish_orders[0])
finished_sandwish.append(sandwish_orders[0])
del sandwish_orders[0]
print ("All sanwishes have been finished")
print (finished_sandwish)