Python Basics Job 1----shopping cart little Practice

Source: Internet
Author: User


Product_list = [
("Iphone", 6000),
("Mac Pro", 12800),
("Bike", 600),
("Watch", 8000),
("book", 24),
("Offee", 35),
]
Shopping_list = ()
Salary = (Input ("Please enter your purchase:"))
If Salary.isdigit (): # To determine if the value entered is numeric, then continue
salary = Int (salary)

While True:
For item in Product_list:
Print (Product_list.index (item), item) # Prints the list's subscript and list

User_choice = input ("Please enter the item number you want to purchase:")
If User_choice.isdigit ():
user_choice = Int (user_choice)


Print ("Input error, please re-enter")
If User_choice <= len (product_list) and User_choice >= 0:
P_item = Product_list[user_choice]
If p_item[1] <= salary: #能够支付
Shopping_list.append (P_item) # is not called. Append, it's drunk.
Salary-= p_item[1]
Print ("The item you purchased was successfully purchased, the balance is still remaining%s"% (p_item[0],salary))

Else
Print ("Not enough balance to buy, please re-select it!")

elif User_choice = = "Exit":
Print ("Exit successful, welcome next time")
Print ("----info of shoppint_list")
For P in Shopping_list:
Print (P)

Print ("Your balance is still remaining", salary)
Print (shopping_list)
Exit ()


Else
Print ("Input value is wrong, please reenter")






Print ()

Python Basics Job 1----shopping cart little Practice

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.