图片是要求,那么开始做吧。
假装我还不会使用def,
其实我现在真的没学def.
product_list = ["1.iphone6s 5800元","2.mac book 9000元","3.coffee 32元","4.python 80元","5.bicyle 1500元"]product_cart = [] salary = int(input("请输入你的工资是多少>>>"))print ("你的工资是:",salary)judge = Truewhile judge == True: print(product_list) product_code = int(input("请输入你要购买的产品编码,退出请输入6>>>")) if product_code == 1: if salary >= 5800: print("恭喜购买成功") product_cart.append(product_list[product_code -1]) salary -=5800 print("你已经购买了",product_cart,"你的余额为",salary) else: print("你买不起,哈哈哈!") elif product_code ==2: if salary >= 9000: print("恭喜购买成功") product_cart.append(product_list[product_code - 1]) salary -= 9000 print("你已经购买了", product_cart, "你的余额为", salary) else: print("你买不起,哈哈哈!") elif product_code ==3: if salary >= 32: print("恭喜购买成功") product_cart.append(product_list[product_code - 1]) salary -= 32 print("你已经购买了", product_cart, "你的余额为", salary) else: print("你买不起,哈哈哈!") elif product_code ==4: if salary >= 80: print("恭喜购买成功") product_cart.append(product_list[product_code - 1]) salary -= 80 print("你已经购买了", product_cart, "你的余额为", salary) else: print("你买不起,哈哈哈!") elif product_code ==5: if salary >= 1500: print("恭喜购买成功") product_cart.append(product_list[product_code - 1]) salary -= 1500 print("你已经购买了", product_cart, "你的余额为", salary) else: print("你买不起,哈哈哈!") elif product_code == 6: judge = False print("你已经购买了", product_cart, "你的余额为", salary)
原文地址:https://www.cnblogs.com/bdua/p/12154626.html
时间: 2024-11-09 10:37:20