• python基础day7_购物车实例


    print("欢迎光临")
    money = input("请输入您的金额:")
    shopping_car ={}
    li = [{"name":"手机","price":2499},
          {"name":"电脑","price":5999},
          {"name":"鼠标垫","price":19},
          {"name":"游艇","price":114900}]
    flag = 1
    if money.isdigit() and int(money) >0:
        money = int(money)
        while flag:
            for i,k in enumerate(li):
                print("{}		{}		{}".format(i,k["name"],k["price"]))
            choice = input("输入选择的商品号(输入Q或者q,退出程序):")
            if choice.isdigit():
                choice = int(choice)
                if choice >= 0 and choice < len(li):
                    # print("对应商品信息:"+li[choice]["name"]+li[choice]["price"])
                    num = int(input("请输入要购买的商品数量:"))
                    if money > num * li[choice]["price"]:
                        money -= li[choice]["price"] * num
                        if li[choice]["name"] in shopping_car:
                            shopping_car[li[choice]["name"]] += num
                        else:
                            shopping_car[li[choice]["name"]] = num
                    else:
                        print("余额不足")
                        break
                    print("购物车中商品有{},您的余额是{}".format(shopping_car,money))
                else:
                    print("输入有误,重新输入")
            elif choice.upper() == 'Q':break
            else:print("请输入数字!")
  • 相关阅读:
    读取radio的value值
    Bootstrap初学(一)
    移动测试用例
    Python 打包成exe执行文件
    Python 模块导入
    Sublime Text2编辑器
    发送Email
    读写TXT文档
    JS与Jquery
    自动化测试摸索
  • 原文地址:https://www.cnblogs.com/Cheryol/p/9606651.html
Copyright © 2020-2023  润新知