Python学习1,代码

来源:http://www.prospettivedarte.com 作者:计算机教程 人气:111 发布时间:2019-05-11
摘要: 看了好久的网上视频,今天尝试着写了一串代码: 皇牌天下投注网,  1 _author_ = "Happyboy" 2 produce_list = [ 3 ('Iphone',5800), 4 ('Mac Pro',9800), 5 ('Bike',800), 6 ('Watch',10600), 7 ('Coffee',31), 8 ('Book',

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

皇牌天下投注网, 

 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")

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

 

本文由皇牌天下投注网发布于计算机教程,转载请注明出处:Python学习1,代码

关键词:

最火资讯