Python job Four

Source: Internet
Author: User

Job Title: Shopping Cart Procedure

    • Job Requirements:

      Data structure: goods = [{"Name": "Computer", "Price": 1999},{"name": "Mouse", "Price": 10},{"name": "Yacht", "Price": 20},{"name": "Beauty", "price" : 998},......] Functional Requirements: Basic requirements: 1, after the start of the program, enter the user name password, let the user enter the salary, and then print the Product List 2, allow the user to purchase goods according to the product number 3, the user selects the goods, the detection balance is enough, enough on the direct debit, enough on the reminder 4, can withdraw at any time, Print purchased goods and balances 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 the expansion needs: 1, the user after the next login, enter the user name password, directly back to the last state, that is the last consumption of the balance or those, re-login to continue to Allow query of previous consumption records

Basic Requirements Code:

Goods = [{"Name": "Computer", "Price": 1999},{"name": "Mouse", "Price": 10},{"name": "Yacht", "Price": 20},{"name": "Beauty", "Price": 998 },]shopping =[]username = [' alex ']passname = [' 123 ']uname = input ("User name:") Pname = input ("Password:") if Username[0]==uname and pas Sname[0]==pname:print ("Login Successful! ") Salary=input (" Enter Payroll: ") if Salary.isdigit (): Salary=int (Salary) while True:for index, ITE M in Enumerate (goods): print (Index,item) user_choice=input ("Choose What to Buy?"). >>>: ") If User_choice.isdigit (): user_choice = Int (user_choice) if User_ Choice < Len (goods) and User_choice>=0:p_item = Goods[user_choice] If p_item[                        "Price"] <= salary:shopping.append (p_item) Salary-= p_item["Price"]                Print ("\033[31;1m%s\033[0m remaining"% (salary)) Else:print ("Insufficient balance") Else                    Print ("Product does not exist") elif User_choice = = ' Q ': print ("----------Shopping list------ ----") for P in Shopping:print (p) print (" Balance remaining \033[31;1m%s\033[0m "% (Salar y)) exit () Else:print ("Invalid Option") Else:print ("Login failed! ")

  

Python job Four

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.