Python编程:从入门到实践(课后习题7)

# 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)

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值