# 7-1 汽车租
car = input("What kind of car do you want to rent: ")
print("Let me see if I can find you a " + car.title())
# 7-2 餐馆订位
restaurant = int(input("How many people are dining: "))
if restaurant >= 8:
print("There is no empty table here.")
else:
print("There are empty tables here.")
# 7-3 10的整数倍
num = int(input("Please enter a number: "))
if num % 10 == 0:
print("This number is a multiple of ten.")
else:
print("This number is not a multiple of ten.")
# 7-4 比萨配料
prompt = "\nPlease enter the ingredients you wanna to add to your pizza."
prompt += "\nEnter 'quit' to indicate that you need the above ingredients."
tf = True
while tf:
ingredients = input(prompt)
if ingredients == 'quit':
tf = False
else:
print(ingredients.title() + " has joined the pizza.")
# 7-5 电影票
prompt = "\nPlease enter your age."
prompt += "\nEnter 'quit' to exit the loop."
while True:
age = int(input(prompt)) # 别忘了加int
if age < 3:
print("For free!")
elif age >=3 and age < 12:
print("10 dollars!")
elif age >= 12:
print("15 dollars!")
else:
print("Wrong input!!!")
break
# 7-8 熟食店
sandwich_orders = ['tuna', 'flossing', 'turkey']
finished_sandwiches = []
while sandwich_orders:
add = sandwich_orders.pop()
print("I made your " + add + " sandwich.")
finished_sandwiches.append(add)
print("\nAll the sandwiches are done, including:")
for sandwich in finished_sandwiches:
print("\t" + sandwich)
# 7-9 五香熏牛肉(pastrami)卖完了
sandwich_orders = ['tuna', 'pastrami', 'flossing', 'pastrami', 'turkey', 'pastrami']
print("The pastrami are sold out!")
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
no_pastrami = str('pastrami' in sandwich_orders)
print(sandwich_orders)
print("\nWhether pastrami is still in sandwich_orders?\n" + no_pastrami)
# 7-10 梦想的度假胜地
places = []
place_active = True
while place_active:
place = input("If you could visit one place in the world, where would you go?")
places.append(place)
another = input("Any places? (yes/no) ")
if another == 'no':
place_active = False
print("Users want to go to the following tourist attractions have the following places: ")
for i in places:
print("\t" + i)
Python编程:从入门到实践(课后习题7)
最新推荐文章于 2024-07-10 17:50:46 发布