Example of the shopping cart program. The number of purchased items can be displayed.

Source: Internet
Author: User

Example of the shopping cart program. The number of purchased items can be displayed.

Goods_list = [("IphoneX", 9000), ("Tesla", 700000), ("Python book", 55 ),
("Coffee", 35), ("Computer", 6999), ("Bitcoin", 67000), ("Food", 20), ("TV", 5000)]
Shopping_car = []
Cost = 0.0


Print ("Welcome to the shopping market, here is your shopping car .")
Print ("You can enter 'q' to quit at anytime .")
Print ("You can enter 'P' to purchase the goods you buy .")
Print ("You can enter's 'to show your shopping car .")
Print ("You can enter 'R' to show the goods list again .")
Print ("Here are the goods list :")
For I, v in enumerate (goods_list, 1 ):
Print (I, ">>>>>>>>>>>>>>>>>", v)

Saving = input ("Please input your salary :")
If saving. isdigit ():
Saving = float (saving)
While True:
Choose = input ("Please enter the goods NO. you want to buy :")
If choose. isdigit ():
Choose = int (choose)

If choose> 0 and choose <= len (goods_list ):

If goods_list [choose-1] [1] <saving:
Shopping_car.append (goods_list [choose-1])
Cost + = goods_list [choose-1] [1]
Saving-= cost
Print ("Adding % s in your shopping car, it costs % f CNY" %
(Goods_list [choose-1] [0], goods_list [choose-1] [1])
Else:
Print ("Not enough money to buy this goods .")
Else:
Print ("Invalid choosen range .")
Elif choose = "q ":
Print ("Thanks for coming! See you next time! ")
Break
Elif choose = "purchase ":
Print ("Here is your shopping car". center (70 ,"-"))
Shopping_car_set = set (shopping_car)
For goods in shopping_car_set:
Print (goods, "------------- NO:", str (shopping_car.count (goods )),
"---------- COSTS:", goods [1] * shopping_car.count (goods ))
Print ("Total cost: % f CNY" % cost)
Print ("Your saving is now % f CNY" % saving)
Break
Elif choose = "r ":
For I, v in enumerate (goods_list, 1 ):
Print (I, ">>>>>>>>>>>>>>>>>", v)
Elif choose = "s ":
For I in shopping_car:
Print (I)
Else:
Print ("Invalid Input. Try again :-)")


 

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.