zoukankan      html  css  js  c++  java
  • learn_1 购买商品练习

    购买商品的小测试

     1 #!/usr/bin/env python3
     2 # -*- coding: utf-8 -*-
     3 #购买商品练习
     4 
     5 proudect_list = [
     6     ("iphone 11", 4999),
     7     ("huawei mate30", 3999),
     8     ("ipad mini5", 2500),
     9     ("k8s book", 198),
    10     ("coffer", 20),
    11     ("bike", 600),
    12 ]
    13 shopping_list = []
    14 user_money = input("请输入你的钱数:")
    15 
    16 #isdigit 判断int为真,则进入下一步
    17 if user_money.isdigit():
    18     user_money = int(user_money)
    19     while True:
    20         #enumerate 方法 可以给列表添加序号
    21         for index, item in enumerate(proudect_list):
    22             print(index+1, item)
    23         user_choice = input("请输入需要购买商品的编号,输入q退出 >>>:")
    24         if user_choice.isdigit():
    25             user_choice = int(user_choice)
    26             if user_choice > 0 and user_choice <= len(proudect_list):
    27                 user_choice = user_choice-1
    28                 p_item = proudect_list[user_choice]
    29                 if int(user_money) >= int(p_item[1]):
    30                     shopping_list.append(p_item)
    31                     user_money -= p_item[1]
    32                     print("购买的商品 %s , 剩余钱数 %s" % (shopping_list, user_money))
    33                 else:
    34                     print("33[41:1m你的钱不够,233333[0m")
    35             else:
    36                 print("输入编号不对,商品不存在")
    37 
    38         elif user_choice == 'q':
    39             print("已经购买的商品 %s , 剩余钱数 %s" % (shopping_list, user_money))
    40             exit()
    41         else:
    42             print("invaild option!!")
    人生天地间,忽如远行客。
  • 相关阅读:
    前端开发框架
    用C#实现的条形码和二维码编码解码器
    Razor视图语法
    asp.net微软图表控件MsChart
    高并发下的Node.js与负载均衡
    GCC知识
    Mongodb学习(安装篇): 在centos下的安装
    代码评审
    构建一个前端库做一个富客户端的基类
    企业级应用架构(NHibernater+Spring.Net+MVC3+WCF)_3.0
  • 原文地址:https://www.cnblogs.com/voua/p/11649139.html
Copyright © 2011-2022 走看看