第七章 用户输入和while循环 作业

本文介绍了Python编程中使用用户输入和while循环的几个实例,包括餐馆座位判断、10的整数倍判断、电影票价格计算、熟食店订单处理和五香烟熏牛肉售罄情况下的订单处理。通过这些例子,展示了如何结合条件语句和循环结构处理用户输入和数据操作。
摘要由CSDN通过智能技术生成
7-2 餐馆定位
num=input("How many poeple will have dinner?\n")
num=int(num)
if num>8:
	print("There is no empty.")
else:
	print("There is a table.")
7-3 10的整数倍
num=input("Please input a number.\n")
num=int(num)
if num%10==0:
	print("The number can be devided by 10.")
else:
	print("The number can not be devided by 10.")
7-5 电影票
while True:
	age=input("Please input your age('quit' for ending)\n")
	if age=='quit':
		break
	age=int(age)
	if age<3:
		print("Your ticket is free.")
	elif age<=12:
		print("Your ticket costs 10 dollars.")
	else:
		print("Your ticket costs 15 dollars.")
7-8 熟食店
sandwich_orders=['tuna','pork','chicken','ham','vegetable','fruit']
finished_sandwiches=[]
while sandwich_orders:
	sandwich=sandwich_orders.pop()
	print("I made your "+sandwich+" sandwich. ")
	finished_sandwiches.append(sandwich)
print(finished_sandwiches)

7-9 五香烟熏牛肉
sandwich_orders=['tuna','pastrami','pork','chicken','pastrami' ,'ham','vegetable','fruit','pastrami']
finished_sandwiches=[]
print("Pastrami sandwiches are sold out.")
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')
while sandwich_orders:
	sandwich=sandwich_orders.pop()
	print("I made your "+sandwich+" sandwich. ")
	finished_sandwiches.append(sandwich)
print(finished_sandwiches)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值