Commit bcdc309a by BellCodeEditor

save project

parent cf9e63fa
Showing with 0 additions and 14 deletions
def xin_cai(): def xin_cai():
total = [] total = []
#建一个空列表,来存储每个菜的价格
while True: while True:
#进入循环,让顾客可以点不止一个菜
unit= input("请输入:") unit= input("请输入:")
#让顾客在后面写上菜价
if unit== 'q': if unit== 'q':
#如果点完菜,按q推出
break break
#结束循环
else: else:
try: try:
unit=float(unit) unit=float(unit)
except: except:
print("请输入一个价格!") print("请输入一个价格!")
#在输入的价格不符合时,告诉顾客输入的不是价格,让顾客再输入一个正常的价格
else: else:
total.append(unit) total.append(unit)
return total return total
#返回total一个数
def sum(money): def sum(money):
zong=0 zong=0
#先让zong赋值为零
for i in money: for i in money:
zong+=i zong+=i
return zong return zong
#返回zong一个数
price=xin_cai() price=xin_cai()
num=sum(price) num=sum(price)
print("您好,您用餐总价是",num,"元。") print("您好,您用餐总价是",num,"元。")
\ No newline at end of file
#告诉顾客用餐的总价
\ 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