Shopping cart program--python

Posted 子觉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shopping cart program--python相关的知识,希望对你有一定的参考价值。

购物车小程序

需求描述如下:

1.提示用户输入薪水

2.用户输入薪水后,打印商品编号、内容及价格

3.提醒用户输入商品代码,若余额大于等于商品价格,可购买;若小于,提示用户余额不足

4.用户输入q ,退出交易,打印用户购买的商品和余额

技术分享图片
#-*-coding:utf-8 -*-

goods_list=[(Iphone,5800),(Mac Pro,12000),(Coffee,31),(Book,81),(Bike,8000)]
goods_bought=[]
salary=input("please input your salary:")
if salary.isdigit():
    salary=int(salary)
    balance=salary
    while True:
        print("This is our goods list:")
        for index,item in (enumerate(goods_list)):
            print(index,item)
        goods_number=(input("please input goods number you want:"))
        if goods_number.isdigit():
            goods_number=int(goods_number)
            if goods_number>=0 and goods_number<(len(goods_list)):
                if goods_list[goods_number][1]<=balance:
                    goods_bought.append(goods_list[goods_number])
                    balance=balance-goods_list[goods_number][1]%(goods_list[goods_number].balance)
                else:
                    print("Your balance %s is not enough!"%balance)
            else:
                print("The goods number %s is not exist!"%goods_number)
        elif goods_number==q:
            print("Your goods are:")
            for item in goods_bought:
                print(item)
            print("your balance is:%s"%balance)
            goods_bought.clear()
            exit()
        else:
            print("Your input is wrong!")
else:
    print("your salary is wrong:")
            
View Code

 

以上是关于Shopping cart program--python的主要内容,如果未能解决你的问题,请参考以下文章

Shopping cart program--python

instance 1:shopping cart

javascript 由iamuchejude创建的Andela购物车测试 - https://repl.it/@iamuchejude/Andela-Shopping-Cart-Test

python----作业0329

cart_购物车小程序

我可以让一个 div 类可点击吗?