pathon列表应用,购物车小程序

 应用列表 知识,创建一个购物车小程序
1
#购物车小程序 2 def print_result(computer_num,bicycle_num,book_num,coffee_num,scissor_num,pencil_num,rest_num): 3 msg1 = ''' 4 You've bought %d computers, %d bicycles, 5 %d python books, %d coffees, 6 %d scissors, %d pencils. 7 Your rest money is:%d 8 9 ''' % (computer_num, bicycle_num, book_num, coffee_num, scissor_num,pencil_num,rest_num) 10 print(msg1) 11 12 13 salary = input("Your salary:") 14 rest_salary = int(salary) 15 goods_list = [] 16 while True: 17 msg = ''' 18 ========================= 19 1. computer 4500 20 2. bicycle 1500 21 3. python book 80 22 4. coffee 32 23 5. scissor 15 24 6. pencil 1 25 q. stop this program 26 ========================= 27 ''' 28 print(msg) 29 selection = input("Input your selection:") 30 if selection == '1': 31 rest_salary -= 4500 32 if rest_salary <= 0: 33 print_result(goods_list.count("computer"), goods_list.count("bicycle") 34 , goods_list.count("python book"), goods_list.count("coffee") 35 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 36 print("You have no enough money,terminated") 37 break 38 else: 39 goods_list.append("computer") 40 print("the rest money is:%d" %rest_salary) 41 continue 42 elif selection == '2': 43 rest_salary -= 1500 44 if rest_salary <= 0: 45 print_result(goods_list.count("computer"), goods_list.count("bicycle") 46 , goods_list.count("python book"), goods_list.count("coffee") 47 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 48 print("You have no enough money,terminated") 49 break 50 else: 51 goods_list.append("bicycle") 52 print("the rest money is:%d" %rest_salary) 53 continue 54 elif selection == '3': 55 rest_salary -= 80 56 if rest_salary <= 0: 57 print_result(goods_list.count("computer"), goods_list.count("bicycle") 58 , goods_list.count("python book"), goods_list.count("coffee") 59 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 60 print("You have no enough money,terminated") 61 break 62 else: 63 goods_list.append("python book") 64 print("the rest money is:%d" %rest_salary) 65 continue 66 elif selection == '4': 67 rest_salary -= 32 68 if rest_salary <= 0: 69 print_result(goods_list.count("computer"), goods_list.count("bicycle") 70 , goods_list.count("python book"), goods_list.count("coffee") 71 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 72 print("You have no enough money,terminated") 73 break 74 else: 75 goods_list.append("coffee") 76 print("the rest money is:%d" %rest_salary) 77 continue 78 elif selection == '5': 79 rest_salary -= 15 80 if rest_salary <= 0: 81 print_result(goods_list.count("computer"), goods_list.count("bicycle") 82 , goods_list.count("python book"), goods_list.count("coffee") 83 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 84 print("You have no enough money,terminated") 85 break 86 else: 87 goods_list.append("scissor") 88 print("the rest money is:%d" %rest_salary) 89 continue 90 elif selection == '6': 91 rest_salary -= 1 92 if rest_salary <= 0: 93 print_result(goods_list.count("computer"), goods_list.count("bicycle") 94 , goods_list.count("python book"), goods_list.count("coffee") 95 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary) 96 print("You have no enough money,terminated") 97 break 98 else: 99 goods_list.append("pencil") 100 print("the rest money is:%d" %rest_salary) 101 continue 102 elif selection == 'q': 103 print_result(goods_list.count("computer"),goods_list.count("bicycle") 104 ,goods_list.count("python book"),goods_list.count("coffee") 105 ,goods_list.count("scissor"),goods_list.count("pencil"),rest_salary) 106 else: 107 print_result(goods_list.count("computer"), goods_list.count("bicycle") 108 , goods_list.count("python book"), goods_list.count("coffee") 109 , goods_list.count("scissor"), goods_list.count("pencil"), rest_salary)

 

posted @ 2019-11-14 10:09  Iceberg_710815  阅读(146)  评论(0编辑  收藏  举报