Python Shopping Cart

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.