Commit bcdc309a by BellCodeEditor

save project

parent cf9e63fa
Showing with 3 additions and 15 deletions
def xin_cai():
total = []
#建一个空列表,来存储每个菜的价格
while True:
#进入循环,让顾客可以点不止一个菜
unit= input("请输入:")
#让顾客在后面写上菜价
if unit== 'q':
#如果点完菜,按q推出
break
#结束循环
else:
try:
unit=float(unit)
except:
print("请输入一个价格!")
#在输入的价格不符合时,告诉顾客输入的不是价格,让顾客再输入一个正常的价格
else:
total.append(unit)
return total
#返回total一个数
def sum(money):
zong=0
#先让zong赋值为零
for i in money:
zong+=i
return zong
#返回zong一个数
price=xin_cai()
num=sum(price)
print("您好,您用餐总价是",num,"元。")
#告诉顾客用餐的总价
\ No newline at end of file
print("您好,您用餐总价是",num,"元。")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment