zoukankan      html  css  js  c++  java
  • 购物车半成品

    
    
     
    '''
    需求:
        1.启动程序后,让用户输入工资,然后打印商品列表
        2.允许用户根据商品编号购买商品
        3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
        4.可随时退出,推出时,打印已购买商品和余额
    '''
    commodity = [("苹果手机",13800),("oppo手机",3800),("皮带手机",800),("杂牌手机",300),("坚果手机",2800),("联想手机",6600),("华为手机",8800)]
    money = 152000
    haveBought = []
    while True:
        print("编号		名称				价格")
        for index,Commodity in enumerate(commodity):
            print(index + 1, "			%s			%d" % ( Commodity[0], Commodity[1]))
        UserInput = input("请输入商品编号:")
        if UserInput.isdigit():
            UserInput = int(UserInput)
            UserInp = UserInput - 1
            if 0 <= UserInp <= (len(commodity)- 1):
                if money > commodity[UserInp][1]:
                    print(commodity[UserInp])
                    money -= commodity[UserInp][1]
                    haveBought.append(commodity[UserInp])
                    print("您刚刚买了 %s 金额为%d  的商品,余额为%d" % (commodity[UserInp][0],commodity[UserInp][1],money))
                    print("您已经购买了%s"% haveBought )
                    byesIn = input("任意键继续/N退出")
                    if byesIn == "N":
                        break
                else:
                    print("您目前的余额不足以购买%s"% (commodity[UserInp][0]))
                    userI = input("您是否要前往充值?请输入Y/N")
                    if userI == 'Y' :
                        break
                    elif userI == 'N' :
                        break
                    else:
                        continue
            else:
                print("您输入的商品没有找到 -_-!")
                continue
    
    
    
     
     
    以上内容作为课堂笔记,如有雷同,请联系于我
  • 相关阅读:
    Redis 数据结构之dict
    分布式一致性算法——paxos
    分布式事务、两阶段提交协议、三阶提交协议
    MySQL主从数据同步延时分析
    MySQL数据丢失情况分析
    INSERT ... ON DUPLICATE KEY UPDATE Syntax
    分布式系统的数据一致性
    分布式系统的BASE理论
    分布式系统的CAP理论
    性能指标体系构建
  • 原文地址:https://www.cnblogs.com/ArtisticMonk/p/8907153.html
Copyright © 2011-2022 走看看