zoukankan      html  css  js  c++  java
  • day1-1

    product_list = [
                    ("电脑",5800),
                    ("phone",4200),
                    ("pen",66),
                    ("book",99),
                    ("watch",10800),
                    ]
    
    salary = input("输入工资:")
    shopping_list = []
    buy_money = 0
    if salary.isdigit():
        salary = int(salary)
        while True:
            for index,value in enumerate(product_list):
                print(index,value)
            
            choice = input("输入产品编号:")
            if choice.isdigit():
                choice = int(choice)
                
                if choice >= 0 and choice < len(product_list):
                    item = product_list[choice]
                    if salary >= item[1]:
                        salary -= item[1]
                        buy_money += item[1]
                        shopping_list.append(item)
                        for i in shopping_list:
                            print (i)
                        print("你当前的余额是%d" % salary)
                    else:
                        print("你当前的余额是%d,可用余额不足" % salary)
                else:
                    print("没有此商品")
            elif choice == 'q':
                print("shopping list".center(50,'-'))
                for i in shopping_list:
                    print(i)
                print("你购物消费%d元,当前的余额是%d" %(buy_money,salary))
                break
            else:
                print("输入'q'或者编号")
    else:
        print("输入错误")
    View Code

    isdigit  判断输入是否由数字组成

    enumerate print 把列表元素的编号和元素打印出来

    append  添加元素方式

    count = 5 
    while count >= 0:
        print("count:%d" % count)
        count -= 1
    else:
        print("跳出循环后打印count: %d" % count)

    结果:

    count:5
    count:4
    count:3
    count:2
    count:1
    count:0
    跳出循环后打印count: -1

  • 相关阅读:
    MySQL操作表中的数据
    mysql查询语句进阶
    mysql基本查询语句
    mysql函数
    mysql约束
    操作MySQL表
    操作MySQL数据库
    mysql视图
    as2 播放停止音效
    as3 深复制
  • 原文地址:https://www.cnblogs.com/yfjly/p/9523064.html
Copyright © 2011-2022 走看看