shopping_list = [ ? ?('Watch', 10000), ? ?('Ihpone', 5800), ? ?('Bicycle', 800), ? ?('Python_book', 65), ? ?('Coffee', 31),]good_list = []salary = input("Input your salary:")def user(): ? ?'''定義用戶''' ? ?for index, item in enumerate(shopping_list): ? ? ? ?print(index, item) ? ?user_choice = input('Input your buy some of product:')def unmber( ): ? ?'''定義unmber這個函數是程序看起來更簡化''' ? ?user() ? ?x = salary ? ?y = user_choice ? ?z = shopping_list ? ?while True: ? ? ?if x.isdigit() or y.isdigit(): ? ? ? ? ? ?x = int(x) ? ? ? ? ? ?y = int(y) ? ? ? ? ? ?if x < len(z) and x >= 0: ? ? ? ? ? ? ? ?s = p_item = z[x] ? ? ? ? ? ? ? ?if s[1] <= x: ? ? ? ? ? ? ? ? ? ?z.append(s) ? ? ? ? ? ? ? ? ? ?x -= s[1] ? ? ? ? ? ? ? ? ? ?print("Added %s in to shopping cart," ? ? ? ? ? ? ? ? ? ? ? ? ?"you current balance is \033[31;1m%s\033[0m"%(s,x)) ? ? ? ? ? ? ? ?else: ? ? ? ? ? ? ? ? ? ?print("your current balance not to buy is %s"%x) ? ? ? ? ? ?else: ? ? ? ? ? ? ? ?print("Your choice in outside shopping_list") ? ? ?elif x or y == 'q': ? ? ? ? ?print('Wlecome again') ? ? ?else: ? ? ? ? ?print('Invalid Option') ? ?return unmber( )
- 1 回答
- 0 關注
- 1214 瀏覽
添加回答
舉報
0/150
提交
取消