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這個(gè)函數(shù)是程序看起來(lái)更簡(jiǎn)化''' ? ?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( )
我這個(gè)用面向過(guò)程怎么寫
qq_木魚_14
2017-09-13 01:13:00