Goods_list = [ {'name':'Apple',' Price':'Ten'}, {'name':'Banana',' Price':' the'}, {'name':'Pineapple',' Price':' -'}, {'name':'Watermelon',' Price':' -'}, {'name':'Grape',' Price':' -'},]shopping_car={}print ("Welcome to the little pink fruit shop! ") Money= Input ("please take out your silver:")ifMoney.isdigit () andint(Money) >0: Flag=True whileflag: forI, KinchEnumerate (goods_list): Print ('serial Number {}, commodity {}, price {}'. Format (i, k['name'], k[' Price'])) Choose= Input ("Please enter the serial number you selected:") ifChoose.isdigit () andint(choose) <Len (goods_list): Num= Input ("Please enter the number of items you want to buy:") ifnum.isdigit ():if int(Money) >int(goods_list[int(choose)] [' Price']) *int(num): money=int(Money)-int(goods_list[int(choose)] [' Price']) *int(num)ifgoods_list[int(choose)] ['name']inchshopping_car:shopping_car[goods_list[int(choose)] ['name']] = shopping_car[goods_list[int(choose)] ['name']] +int(num)Else: shopping_car[goods_list[int(choose)] ['name']] =int(num) print ("The item in the shopping cart has {}, your balance is {}". Format (Shopping_car, Money)) print ("If you want to leave please press Q or Q, welcome to the next visit! ") Else: Print ("Poor bastards , get out of the code and make money! ") Break Else: Print ("Please enter a number, thank you! ") elif Choose.upper ()=="Q": Flag=False Print ("your current shopping cart is {} and the balance is {}". Format (Shopping_car, money))Else: Print ("Idiot, enter the number!!! ")
Python Shopping Cart