Program: Shopping Cart Program
Demand:
- After you start the program, let the user enter the payroll, and then print the list of items
- Allow users to purchase items based on their product number
- After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
- You can exit at any time to print the purchased goods and balances when exiting
#coding =utf-8#version:python 3.6.0#tools:pycharm 2017.3.2_date_ = ' 2018/4/16/016 14:50 ' _author_ = ' Hongyong ' salary = Int (Input ("Please input your Salary:")) Shoppingmart = []items = (["1.", "Huawei", "¥", 2800], ["2.", "earphone", "¥", ["3.", "book", "¥", "+]") print (items) while True: shopindex = int (Input ("Choose Goods:")) if Salary > Items[shopindex-1][3]: shoppingmart.append (items[shopindex-1]) Salary-= Int (items[shopindex-1 ][3]) print ("You have bought {name}!". Format (name = Items[shopindex-1][1])) print ("Your balance Is:¥", salary) decision = input ("Do you want-quit now ?") If decision = = "Q": Break Else: continue Else: print ("Your balance are not enough! Please try sth else. ") Print ("You have bought", Shoppingmart)
The second day of Python medicine--Shopping cart procedure