码迷,mamicode.com
首页 > 编程语言 > 详细

Shopping cart program--python

时间:2018-10-16 13:51:36      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:list   while   book   app   lease   [1]   交易   需求   this   

购物车小程序

需求描述如下:

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

标签:list   while   book   app   lease   [1]   交易   需求   this   

原文地址:https://www.cnblogs.com/zijue/p/9797047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!