python作业之购物车详解编程语言
2023-06-13 09:11:54 时间
shop_house = ["小米手机:2001", "苹果手机:5330", "三星手机:4103", "华为手机:3125", "魅族手机:3973", "联想手机:222", "酷派手机:155", "退出", "买单"] wel = "welcome to Cevin phone shopping house" total_money = 120000 shop_car_dict = {} iphone_num = 0 xiaomi_num = 0 sanxing_num = 0 huawei_num = 0 meizu_num = 0 lianxiang_num = 0 kupai_num = 0 while True: print(wel.center(80, -)) for i, phone in enumerate(shop_house): print(i, phone) option = input("which phone do you want to buy?") if option == "0": per = shop_house[0].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): xiaomi_num += 1 per_dict = {per[0]: {"总价": int(per[1])*xiaomi_num, "数量": xiaomi_num,"单价":int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: xiaomi_num = 1 per_dict = {per[0]: {"总价": int(per[1])*xiaomi_num, "数量": xiaomi_num,"单价":int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "1": per = shop_house[1].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): iphone_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * iphone_num, "数量": iphone_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: iphone_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * iphone_num, "数量": iphone_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "2": per = shop_house[2].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): sanxing_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * sanxing_num, "数量": sanxing_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: sanxing_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * sanxing_num, "数量": sanxing_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "3": per = shop_house[3].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): huawei_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * huawei_num, "数量": huawei_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: huawei_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * huawei_num, "数量": huawei_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "4": per = shop_house[4].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): meizu_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * meizu_num, "数量": meizu_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: meizu_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * meizu_num, "数量": meizu_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "5": per = shop_house[5].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): lianxiang_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * lianxiang_num, "数量": lianxiang_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: lianxiang_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * lianxiang_num, "数量": lianxiang_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "6": per = shop_house[6].split(":") if total_money = int(per[1]): total_money = total_money - int(per[1]) # print(-.center("50")) print("%s is in shop_car,and you money is %d" % (per[0], total_money)) if shop_car_dict.get(per[0]): kupai_num += 1 per_dict = {per[0]: {"总价": int(per[1]) * kupai_num, "数量": kupai_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: kupai_num = 1 per_dict = {per[0]: {"总价": int(per[1]) * kupai_num, "数量": kupai_num, "单价": int(per[1])}} shop_car_dict.update(per_dict) print(shop_car_dict) else: print("sorry your money is not enough!") elif option == "7": while True: option = input("are you sure to exit?/n1:退出/n2:返回") if option == "1": print("ByeBye") exit() elif option == "2": break else: print("input error") continue
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20906.html
cpython
相关文章
- python生成器详解_Python 生成器
- python在线代码编辑器-5种最佳Python IDE和代码编辑器
- Python标识符的命名规则,下列哪些是对的?_python标识符不能使用关键字
- Python赢得TIOBE年度编程语言(2020年)
- 用几行Python代码实现一个简单的Web服务器详解编程语言
- 十进制转化为二进制的Python 3.2 代码详解编程语言
- python用来获得图片exif信息的库代码详解编程语言
- python返回汉字的首字母详解编程语言
- python实现的代码行数统计代码详解编程语言
- Python 输出斐波纳挈数列详解编程语言
- 利用python 统计源码行数详解编程语言
- python中的字典用法示例详解编程语言
- Python sql server和postgresql的表结构转换详解编程语言
- Python开发系列课程(16) – 进程和线程详解编程语言
- Python开发系列课程(8) – 字符串和常用数据结构详解编程语言
- Python IO编程——学习笔记详解编程语言
- Python json模块dumps loads详解编程语言
- Python 判断文件是否存在的三种方法详解编程语言
- Python时间,日期,时间戳之间转换,时间转换时间戳,Python时间戳转换时间,Python时间转换时间戳详解编程语言
- python:继承和多态详解编程语言
- python工具——Mimesis详解编程语言
- python的redis简单使用详解编程语言
- python的memory_profiler模块使用详解编程语言
- python之多线程队列详解编程语言
- python的json模块的dumps,loads,dump,load方法介绍详解编程语言
- Python写的一个简单DNS服务器实例