#!/usr/bin/Env python#-*-coding:utf-8-*-# Author:DaShuang.Gu" "Requirements:Buyers1. Product information exists in the file2. Purchased goods, Balance records. The first time you start a program, you need to record your salary, and the second time you start the program, the last balance is displayed3. Allow users to purchase items based on their product number4after the user selects the product, the detection is enough, enough on the direct debit, enough to remind5. Can exit at any time, when exiting, print move purchase goods and balances merchant entrance: Can add goods, modify commodity price, run program output first level menu" "Product_list = [ ('Iphone',5800), ('Mac Pro',9800), ('Bike', -), ('Watch',10600), ('Coffee', to), ('Alex Python', -),]shopping_list=[]user_salary= Input ("Please enter your salary:")ifuser_salary.isdigit (): User_salary=int(user_salary) whileTrue: #打印出商品信息 print ('Product List'. Center ( -,'*')) forIndex,iteminchEnumerate (product_list): Print (index,item) # BreakShopping_number= Input ("output The item number you want to buy:") ifshopping_number.isdigit (): Shopping_number=int(Shopping_number)ifShopping_number < Len (product_list) and Shopping_number >=0: P_item=Product_list[shopping_number]ifUser_salary >= p_item[1]: Shopping_list.append (p_item) user_salary-= p_item[1] Print ("product%s added to cart with balance%s"%(P_item, user_salary))Else: Print ('Insufficient balance%s'%user_salary)Else: Print ('the product number entered does not exist') elif Shopping_number=='Q': Print ('Shopping list'. Center ( -,'*')) forIinchshopping_list:print (i) Print ("also multiply the balance%s"%user_salary) exit ()
Python Automation development-ex03 (shopping cart implementation)