购物车简例

# v# -*- coding: utf-8 -*-
# """
# Created on Fri Aug 23 14:23:55 2019
#
# @author: ITS
# """
#
# total_money = int(input('user money:\n'))
# goods = [
#     {"name": "电脑", "price": 1999},
#     {"name": "鼠标", "price": 10},
#     {"name": "游艇", "price": 20},
#     {"name": "美女", "price": 998},
# ]
# buylist_id=[]
# buylist = []
# goods_list = []
# money = []
# goods_money = 0
#
# def listgoods():
#     for i in goods:
#         print(i)
#
# def addcar():
#     global goods_money,goods_list
#     i = int(input('choose your goods index:\n'))
#     if i not in range(len(goods)):
#         print("error , no good there")
#     else:
#         buylist.append(goods[i])
#         buylist_id.append(i)
#         print(buylist_id)
#         goods_list=buylist[:]
#         print(goods_list)
#     CHOICE = input('continue buy? : Y/N\n')
#     if CHOICE == 'Y':
#         addcar()
#     elif CHOICE == 'N':
#         print('jiesuanzhong')
#
#
#
#     return buylist_id,buylist,goods_list,goods_money
#
# def jiesuan():
#     global total_money,goods_list,goods_money
#     for i in range(len(goods_list)):
#         money.append(goods_list[i]['price'])
#     #print(money)
#     for item in money:
#         goods_money += item
#     print(goods_money)
#     while goods_money>total_money:
#         CHOICE = input('addmoney? : Y/N\n')
#         if CHOICE == 'Y':
#             num = int(input('choose your addmoney number:\n'))
#             addmoney(num)
#             while goods_money>total_money:
#                 num1 = int(input('please continue addmoney:\n'))
#                 addmoney(num1)
#             total_money-=goods_money
#             #print('total_money:',total_money)
#             print('purchase success, rest_money:',total_money)
#             break
#
#         elif CHOICE == 'N':
#             choice = input("remove some goods? : Y/N\n")
#             if choice == 'Y':
#                 print(buylist_id)
#                 i = int(input('choose your remove good: \n'))
#                 if i not in buylist_id:
#                     print('error, have not chosen this good')
#                 elif i in buylist_id:
#                     buylist_id.remove(i)
#                     print(buylist_id)
#                     item = 0
#                     new_total_money= []
#                     for i in buylist_id:
#                         new_total_money.append(goods[i]['price'])
#                     for new_money in new_total_money :
#                         item += new_money
#                         goods_money=item
#                     print(goods_money)
#                     total_money-=goods_money
#                     print('purchase success, rest money:',total_money)
#                     break
#             elif choice == 'N':
#                 print('purchase failed')
#                 break
#
# def addmoney(num):
#     global total_money
#     total_money += num
#     return total_money
#
#
# if __name__ == "__main__":
#     addcar()
#     jiesuan()

  

你可能感兴趣的