1Goods = [2('IPhone', 5888),3('Mac Pro', 12888),4('IWatch', 2888),5('Bike', 888),6('Cofe', 16),7(' Book', 85)8 ]9money = Int (input ("Please Input your money:"))TenBuylist = [] One whileTrue: A Print('Product List'. Center (30,'-')) - forIndex,itemsinchEnumerate (goods): -Name,price =Items the Print(Index,name,price) -User_choice = input ('Please input your choice:') - ifuser_choice.isdigit (): -User_choice =Int (user_choice) + ifUser_choice < Len (goods) andUser_choice >=0: - ifMoney > Goods[user_choice][1]: +Money-= goods[user_choice][1] ABuylist.append (('%s,%s')% (goods[user_choice][0],goods[user_choice][1]) ) at Else: -Choice = input ('The money is not enough,continue?') - ifChoice = ='y': - Continue - Else: - Print('your Shopping cart has:') in forInfoinchbuylist: - Print(Info) toExit'your balance is:%s'%Money ) + Else: - Print('input Error, retry') the Continue * elifUser_choice = ='Q': $ ifLen (buylist) = =0:Panax NotoginsengExit'you have not purchased anything, and your balance is:%s'%Money ) - Else: the Print('your Shopping cart has:') + forInfoinchbuylist: A Print(Info) the Print('your balance is:%s'%Money ) + Else: - Print('\033[31;1minput error,retry\033[0m') $ Continue
Python mini-Program Shopping Cart