“购物车”练习

Emm....

It's a shopping cart;

1.You need input your salary;

2.Output a products list,each product mast contain a sequence number;

3.You need input thr sequence number what you want to buy,if you input "q" print your shopping  list and your saving(salary);

4;Your salary must enough to add product to your shopping list,if not ...

Here is my code:

 1 salary =  input("input Your salary:")
 2 product = [
 3     ('iphone',6000),
 4     ('Mac Pro',14000),
 5     ('mouse',100),
 6     ('keyboar',300),
 7     ('XiaoMi 2s',3000),
 8 ]
 9 p_list = []
10 while salary.isdigit():
11     salary=int(salary)
12     while True:
13         for index, item in enumerate(product):
14             print(index, item)
15         user_choose = input("input the num of product what You want wo buy:")
16         if user_choose.isdigit():
17             user_choose = int(user_choose)
18             if user_choose >= 0 and user_choose < len(product):
19                 if salary >= product[user_choose][1]:
20                     p_list.append(product[user_choose])
21                     salary -= product[user_choose][1]
22                     print("\033[1;42m The product added in Your shopping list \033[0m!")
23                 else:
24                     print("\033[1;41m Your salary is not enough;have try other product \033[0m!")
25             else:
26                 print("\033[1;41m Your inputted out of list \033[0m!")
27         elif user_choose == "q":
28             print("Your shoppong list:%s,Your salary is %s" % (p_list, salary))
29             exit()
30         else:
31             print("\033 [1;41m Your invalid option;choose again \033[0m!")
32 else:
33     print("输入错误")

it takes me all night long...  so stupid... hah..

猜你喜欢

转载自www.cnblogs.com/jipyu/p/9238096.html