Python编程:从入门到实践(课后习题7)
2017-09-19 11:04
465 查看
# 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编程 从入门到实践》第八章课后习题
- 《Python编程-从入门到实践》课后习题(6)
- Python编程:从入门到实践(课后习题3)
- 《Python编程 从入门到实践》第十章课后习题
- 《Python编程-从入门到实践》课后习题(2)
- Python编程:从入门到实践(课后习题5)
- 《Python编程 从入门到实践》第九章课后习题
- 《Python编程 从入门到实践》第三章课后习题
- Python编程:从入门到实践(课后习题6)
- Python编程:从入门到实践(课后习题8)
- 《Python编程 从入门到实践》第二章课后习题
- 《Python编程-从入门到实践》课后习题(1)
- Python编程:从入门到实践(课后习题9)
- 《Python编程-从入门到实践》课后习题(8)
- 《Python编程 从入门到实践》第五章课后习题
- 《Python编程-从入门到实践》课后习题(5)
- Python编程:从入门到实践(课后习题11)
- 《Python编程-从入门到实践》课后习题(7)
- 《Python编程 从入门到实践》第六章课后习题
- Python编程:从入门到实践(课后习题10)