赞
踩
# 创建一个点餐空列表 orderlist = [] # 主菜单 def main(): # while死循环 while True: # 打印主菜单 print('------------欢迎使用点餐系统------------\n本软件提供如下功能:') lis = ['1. 点餐', '2. 打印报表', '3. 存储报表', '4. 退出系统'] for i in lis: print(i) # 接收用户输入 a = int(input('请输入数字选择一项功能:')) if a == 1: print('开始点餐') # 调用点餐函数 order_food() continue elif a == 2: print('正在打印报表') # 调用打印报表函数 print_report() continue elif a == 3: print('正在存储报表') # 调用存储报表函数 save_report() continue elif a == 4: print('成功退出系统') # 退出循环 break else: print('输入错误请重新输入!!') continue # 点餐 def order_food(): flag = 1 while True: print("---------欢迎点餐---------\n我们提供的饮品:") lis = ['1. 豆浆', '2. 果汁', '3. 牛奶', '0. 不选'] for i in lis: print(i) print() # 创建餐饮字典 item = {"豆浆": 3.00, "果汁": 4.50, "牛奶": 3.00, "馒头": 1.00, "包子": 2.50, "鸡蛋": 1.50, "油条": 2.00, " ": 0.00} # 创建空列表,存放饮品价格 liste = [] # 创建饮品列表 ypi = [] a = int(input('请输入序号选择您需要的饮品:')) if a == 1: print('您选择了豆浆') dj = item["豆浆"] ypi = ["豆浆"] liste = [dj] elif a == 2: print('您选择了果汁') gz = item["果汁"] ypi = ["果汁"] liste = [gz] elif a == 3: print('您选择了牛奶') nn = item["牛奶"] ypi = ["牛奶"] liste = [nn] elif a == 0: print('不选择') k = item[" "] ypi = [" "] liste = [k] else: print('输入错误') print() print('我们提供的食品:') liss = ['1. 馒头', '2. 包子', '3. 鸡蛋', '4. 油条', '0. 不选'] for i in liss: print(i) # 创建空列表,存放食品价格 new_liste = [] # 创建食品列表 spin = [] b = int(input('请输入序号选择您需要的食品:')) if b in [1]: print('您选择了馒头') mt = item["馒头"] spin = ["馒头"] new_liste = [mt] elif b in [2]: print('您选择了包子') bz = item["包子"] spin = ["包子"] new_liste = [bz] elif b in [3]: print('您选择了鸡蛋') jd = item["鸡蛋"] spin = ["鸡蛋"] new_liste = [jd] elif b in [4]: print('您选择了油条') yt = item["油条"] spin = ["油条"] new_liste = [yt] elif b in [0]: print('不选择') ko = item[" "] spin = [" "] new_liste = [ko] # 定义一个flag flag = 0 for i in liste: if i >= 1: print('饮料费用:¥{:.2f}'.format(float(i))) else: print() for i in new_liste: if i >= 1: print('食物费用:¥{:.2f}'.format(float(i))) else: print() print() money = liste[0] + new_liste[0] if money < 1: gg = ["", "", ""] else: gg = [ypi[0], spin[0], money] orderlist.append(gg) else: print('输入错误') # flag为0,跳出循环 if flag == 0: break else: for i in liste: if i >= 1: print('饮料费用:¥{:.2f}'.format(float(i))) else: print() for i in new_liste: if i >= 1: print('食物费用:¥{:.2f}'.format(float(i))) else: print() money = liste[0] + new_liste[0] if money < 1: gg = ["", "", ""] else: gg = [ypi[0],spin[0],money] orderlist.append(gg) # 打印报表 def print_report(): print('--------统计报表--------') print('饮料\t\t\t食物\t\t\t花费(元)') # 定义一个变量 Expenses = 0 # orderlist为空则什么也不做 if not orderlist: pass else: for i in orderlist: for j in i: print(j, end='\t\t\t') print() try: # Expenses = Expenses + i[2] Expenses += i[2] except: pass print() # 打印Expenses{:.2f}为两位小数 print('累计费用:{:.2f}元'.format(Expenses)) print() # 存储报表 def save_report(): with open('Report_file', 'w+', encoding='utf-8') as file_obj: # 写入表头 file_obj.write('饮料\t\t\t食品\t\t\t花费(元)') # 写入换行 file_obj.write('\n') # 重复打印报表 Expenses = 0 if not orderlist: pass else: for i in orderlist: for j in i: file_obj.write(str(j)+'\t\t\t') try: Expenses += i[2] file_obj.write('\n') except: pass file_obj.write('\n') file_obj.write('\t\t\t\t累计费用:{:.2f}元'.format(Expenses)) print('\n\n------存储完成!\n') # 调用主菜单函数 if __name__ == '__main__': main()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。