Python Shopping Cart Program

Source: Internet
Author: User

Python Code Note points:
1. Note Indent
2.if, while and other statements remember to add a colon:
3. Note the use of spaces
4. When writing code through PYCHARM, note the prompt information

Data:
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
......
]

Functional Requirements:
Basic requirements:
1, after starting the program, enter the user name password, let the user enter the salary, and then print the product list
2. Allow users to purchase goods according to the product number
3, the user selects the goods, checks whether the balance is enough, enough on the direct debit, not enough on the reminder
4, can withdraw at any time, exit, print purchased goods and balance
5, in the user process, the key output, such as the balance, the product has been added to the shopping cart and other messages, need to highlight

Expansion requirements:
1, the user after the next login, enter the user name password, directly back to the last state, that is, the balance of the last consumption or those, re-login to continue to purchase
2, allow to query the previous consumption record
(pending update)
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998}
]
info = {' Zhang San ': ' Qaz ', ' John Doe ': ' Qaz ', ' Harry ': ' Qaz ', ' Zhao Liu ': ' Qaz '}
list = []

user = input (' \033[0m\033[0m Please enter username: ')
If user in info:
passwd = input (' \033[0m\033[0m Please enter password: ')

if passwd = = Info[user]: wage = input (' \033[0m\033[0m Please enter your salary: ') if Wage.isdigit (): #判断工资是否为数字 WA GE = int (wage) else:print (' \033[0m\033[0m Please enter Number ') while True:for I,index in Enumerate (goods): #打印商品 List print (i,index) cart = input (' \033[0m\033[0m Please enter the product number you want to purchase ') if Cart.isdigit (): Cart                    = Int (cart) if cart <= len (goods): If wage-goods[cart][' price ' < 0: Print (' \033[1;32;40m balance insufficient ') Else:wage = wage-goods[cart][' price '] Li                St.append (goods[cart][' name ') # Save purchased item print (' \033[1;32;40m item has been added to Cart ') Else: Print (' \033[0m\033[0m no product number ') elif cart = = ' Q ': Print (' \033[1;32;40m has purchased the following product ', list) print (' \033[1;32;40 Your balance is: ', wage) break else:print (' \033[0m\033[0m no product number ') Else:print (' \033[0 m\033[0m Password error ')

else:
Print (' \033[0m\033[0m user name error ')

Python Shopping Cart Program

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.