Python学习1,代码

2018-06-18 02:27:15来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

  看了好久的网上视频,今天尝试着写了一串代码:

 

 1 _author_ = "Happyboy"
 2 produce_list = [
 3     ('Iphone',5800),
 4     ('Mac Pro',9800),
 5     ('Bike',800),
 6     ('Watch',10600),
 7     ('Coffee',31),
 8     ('Book',120)
 9     ]
10 shopping_list = []
11 salary = input("Input your salary:")
12 if salary.isdigit():
13      salary = int(salary)
14      while True:
15          for index,item in enumerate(produce_list):
16             print(index,item)
17          user_choice = input("选择要买吗?>>>:?")
18          if user_choice.isdigit():
19             user_choice = int(user_choice)
20             if  user_choice < len(produce_list) and user_choice >=0:
21                p_item = produce_list[user_choice]
22                if p_item[1] <= salary : #买得起
23                    shopping_list.append(p_item)
24                    salary -= p_item[1]
25                    print("Added %s into shopping cart,your current balance is \033[31;1m%s\033[0m"%(p_item,salary))
26                else:
27                    print("\033[41;1m你的余额只剩[%s]\033[0m"% salary)
28             else:
29                    print("prodct code [%s] is not exist"% user_choice)
30          elif user_choice =="q":
31               print("--------shooping list-------")
32               for p in shopping_list:
33                   print(p)
34               print("Your current balance:",salary)
35               exit()
36          else:
37               print("invalid option")

 如果可以缩短,或者精炼的麻烦各位大牛帮我看下。。

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python3 报错:UnicodeDecodeError: &#39;utf-8&#39; codec

下一篇:python--inspect模块