Requirements:
User Portal:
- Product information exists in the file
- User input user name and password login, if for the first time login, then enter the user's salary, print the goods can be purchased
- The user chooses the goods which need to purchase according to the salary, if buys successfully, then the debit. If you don't have enough pay to buy this item, a reminder is displayed
- Users can exit at any time and print the list of items that the user has purchased when exiting
- After the user exits, record the user's purchased goods and balance records.
- The next time you log in, you can continue to purchase based on your last balance
Merchant entrance
#!/usr/bin/env python#-*-coding:utf-8-*-#Author JiangImportOs,sysprodt='E:\python\pythonhomework2\product.txt'User=r'E:\python\pythonhomework2\users.txt'Pro_file=open (Prodt,'r+')#Convert a product file into a listpro_list=Pro_file.readlines () forLine1inchPro_list:product,price=Line1.strip (). Split () Pro_file.close ( ) use=open (User,'r+')#convert a file containing user information into a dictionaryDic=dict () forLineinchUse:line=line.strip (). Split (' ') Dic[line[0]]=line[1:]use.close () name=input ('Please enter user name:') Flag1=True whileFlag1: forKeyinchDIC:ifkey==Name:password=input ('Please enter your password:') ifpassword==Dic[key][0]:Print('your current balance is%s, you have purchased the following items:%s'% (dic[key][1],dic[key][2:])) Print('the list of items available for purchase is as follows:') forIndex,itemsinchEnumerate (pro_list):Print(index+1, items) num=input ('Please enter product number:') ifnum.isdigit (): Num=int (num)ifDic[key][1]>price[num-1]: dic[key][1]-=price[num-1] Print('you have successfully purchased the%s product and your balance is%s'% (Product[num-1],dic[key][1]))
:
- Merchants can add products, modify the price of goods
Python's Shopping Cart