#作业3: Shopping Cart Program
#启动程序后, let the user enter the payroll, and then print the list of items
#允许用户根据商品编号购买商品
#用户选择商品后, check whether the balance is enough, enough to direct debit, not enough to remind
#用户可以一直购买商品, you can also exit at any time, when you exit, print the goods and balances you have purchased
# ideas. part1
# to use formatted output
# to use the loop
# First make a list of items, the index number corresponds to the product
# Get another product dictionary, the price of the goods
# Reviews Ideas:
# A list A dictionary, change inconvenient, and association inconvenient, should use a list to save a heap of tuples
# No need to use formatted output, print the list directly
# also need to create an empty list to save the elements that have already been selected
#
# ideas. Part2
# Enter Payroll
# Input Options
# if it's a number
# Check balance, debit
# Otherwise reminders until the balance is not enough keep reminding
# If it's quitting,
# exit
# otherwise error
# Reviews Ideas:
# The wage you enter needs to be judged whether it is a number
# The input option also needs to be judged whether it is a number or quit
# Nesting of conditional judgments is critical, where is it opened? Look at the terminating line, backward from the terminating line
# If you enter an error at the beginning, you need to terminate it immediately, so start with the first input judgment
# ideas. Part3
# Set a judgment bit to control when the while loop is interrupted
# Set a cost value to save how much money you spent
# need to determine if the number entered is out of range
Item_list = [(' iphone ', 6800), (' Swatch ', +), (' Book ', ' Max '), (' Apple ', ten), (' Radio ', 500)]
Your_list = []
Your_cost = 0
Salary = input ("Please input your salary:\n")
If Salary.isdigit ():
salary = Int (salary)
Judge = True
While Judge:
Print ("The Item list is:")
For Index,item in Enumerate (item_list):
Print (Index+1,item)
Your_choice = input ("Please input your choice (q): \ n")
If Your_choice.isdigit ():
your_choice = Int (your_choice)
If Your_choice <= len (item_list):
your_choice = Int (your_choice)-1
If salary >= item_list[your_choice][1]:
Salary-= item_list[your_choice][1]
Your_cost + = item_list[your_choice][1]
Your_list.append (Item_list[your_choice])
Print ("You had%d left"% (salary))
Print ("Your choice is:")
For index, item in enumerate (your_list):
Print (index + 1, item)
Else
Print ("Your money is no enough.")
Print ("You had%d left"% (salary))
Else
Print ("Invalid input.out of Range")
elif Your_choice = = "Q" or "Q":
Print ("Thank for Your choice.")
Print (' Your cost is%d ' '% (your_cost))
Judge = False
Else
Print ("Invalid Input")
Else
Print ("Invalid Input")
Python Job 3: Shopping Cart Program