store={'Rice':450,'Beans':200,'Egg':40,'Fish':250,'Spag':250}
bill=()
total=()
print('Welcome!!!we sell:',"\n",[store])
while True:
a=input('What would you like to buy?=')
b=input('how many of each product do you want?=')
if a in store:
bill=store[a]*b
print('bill=',bill)
elif a not in store:
print('Sorry we don\'t have that')
else:
total=bill+total
print('Total=',total)
你的
if/elif/else
是不可能的,因为无论a
是否在字典中,你都无法进入else
,所以把它放在if
中我还添加了一种通过输入
stop
来停止循环的方法,如果没有,您将无法停止程序并打印最终的total
将
b
输入移动到if
中,如果产品不可用,则无需询问数量在
b
上添加了int()
转换相关问题 更多 >
编程相关推荐