5. A brief discussion of Python's simple shopping cart

Source: Internet
Author: User

Simple Shopping cart Function: Enter the existing amount, choose shopping, determine whether the amount is sufficient, end printing the current purchases, the remaining amount, etc.

Goods_list = ((' Tesla ', 900000), (' Mate ', 4000), (' Apple X ', 7000), (' bens ', 1000000), (' movie ', ' Max '), (' Bicycle ', 1500))
Shopping_car = []
Print (' ========== Welcome to my shop ========== ')
For i,v in Enumerate (goods_list,1):
Print (I, '--', V)
Print (' ========================================== ')
saving = input (' Please input your saving: ')
If Saving.isdigit ():
saving = Int (saving)
While True:
Choice = input (' Plesse input your choice: ')
If Choice.isdigit ():
Choice = Int (choice)
If Choice>0 and Choice<=len (goods_list):
Choice_goods = goods_list[choice-1]
#print (Choice_goods)
If saving >= choice_goods[1]:
SAVING-=CHOICE_GOODS[1]
Shopping_car.append (Choice_goods)
Else
Print (' Please input correct number! ')
elif Choice = = ' Q ':
Print (' ============ your shopping car ============ ')
For I in Shopping_car:
Print (i)
Print (' You hava%s '%saving)
Break
Else
Print (' Please input correct number! ')

Else
Print (' Please input correct number! ')

5. A brief discussion of Python's simple shopping cart

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.