购物车小程序的实现 python 进阶第五课

Posted 三道_python

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物车小程序的实现 python 进阶第五课相关的知识,希望对你有一定的参考价值。

product_list = ["1.iphone6s 5800元","2.mac book 9000元","3.coffee 32元","4.python 80元","5.bicyle 1500元"]
product_cart = []
def sales(code,price):
    if salary >= price:
        print("恭喜购买成功")
        product_cart.append(product_list[code - 1])
        salary -= price
        print("你已经购买了", product_cart, "你的余额为", salary)
    else:
        print("你买不起,哈哈哈!")
salary = int(input("请输入你的工资是多少>>>"))
print ("你的工资是:",salary)
judge = True
while judge == True:
    print(product_list)
    product_code = int(input("请输入你要购买的产品编码,退出请输入6>>>"))
    if product_code == 1:
        product_much = 5800
        sales(product_code,product_much)
    elif product_code == 2:
        product_much = 9000
        sales(product_code, product_much)
    elif product_code == 3:
        product_much = 32
        sales(product_code, product_much)
    elif product_code ==4:
        product_much = 80
        sales(product_code, product_much)
    elif product_code == 5:
        product_much = 1500
        sales(product_code, product_much)
    elif product_code == 6:
        judge = False
        print("你已经购买了", product_cart, "你的余额为", salary)
        print("欢迎下次光临!")
    else:
        print("输入错误,请重试!")

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 = True
while 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)
print("欢迎下次光临!")

以上是关于购物车小程序的实现 python 进阶第五课的主要内容,如果未能解决你的问题,请参考以下文章

产品经理进阶第五课,Axure实操之动态面板的进度条效果

产品经理进阶第五课,Axure实操之动态面板的进度条效果

微信小程序自学第五课:条件渲染列表渲染

Python 基础 2022 最新第五课 函数

Python 基础 2022 最新第五课 函数

Python 基础 2022 最新第五课 函数