Python's Shopping Cart

Source: Internet
Author: User

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

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.