Python program to write shopping applet

Source: Internet
Author: User

Shopping Cart Requirements:
       The user name and password are stored in the file to       start the program, log in, log in successfully let the user enter the salary, and then print the list of items, failure to log in again, more than three times the exit program       allows users to buy goods based on the product number of the       user to select goods, check the balance is sufficient, Enough to direct debit, not enough on the reminder       can be withdrawn at any time, exit, print purchased goods and balances
#!/usr/bin/env python#-*-coding:utf-8-*-"' username and password are stored in the file to start the program, log in, log in successfully let the user enter the salary, and then print the product list, failed to re-login,                More than three times the exit program allows users to buy goods according to the product number of the user to select goods, check whether the balance is enough, enough on the direct debit, not enough on the reminder can withdraw at any time, exit, print the purchased goods and balance ' product_dic = {1:[' Iphone7 ', 5800],                2:[' Coffee ', 30], 3:[' pimple soup ', [ten], 4:[' Python book ',], 5:[' Bike ', 199], 6:[' ViVo X9 ', 2499],}shop_list=[]shop_dic={}def Shop (): tag=true remain_balance = Balance print ("Start shopping". C Enter ("=")) for Key,value in Product_dic.items (): Print (Key,value) while Tag:serial_number=input ("            Enter the number of the item you want to buy >>: "). Strip () if Serial_number.isdigit (): serial_number = Int (serial_number)            If Serial_number > 6:print ("Please enter 1-6") Continue elif serial_number = "Q": Print ("Start Checkout". Center ("=")) for list in shop_list:product_name = list[0] pr Oduct_price = list[1] Shop_dic.sEtdefault (Product_Name, {}) Shop_dic[product_name].setdefault ("number", 0) shop_dic[product_  Name].setdefault ("Total", 0) shop_dic[product_name]["price"] = Product_price if product_name In shop_dic:shop_dic[product_name]["number"] + = 1 shop_dic[product_name]["Total" = sh op_dic[product_name]["Price"] * shop_dic[product_name]["number"] # gross = 0 for produ CT in Shop_dic:print (Product.center (7), str (shop_dic[product]["number"]). Center (7), str (shop_dic[product]["t            Otal "]). Center (5)) Total = Total + shop_dic[product][" Total "] # if > Balance:            # print ("Insufficient balance to buy so much") break elif Serial_number = = "Exit": Print ("direct exit") Else: Continue print ("You want to buy the product number {}, commodity {}, Price {}". Format (Serial_number,product_dic.get (serial_number) [0],PRODUCT_DIC.G  ET (Serial_number) [1])      Yes_no=input ("Input y/n, OK to add to cart >>:") if yes_no = = "Y": If Product_dic.get (Serial_number) [1] ;            Remain_balance:print ("Your balance is not enough. Unable to add to cart, not yet {}". Format (Product_dic.get (serial_number) [1]-remain_balance)] Else:shop_list.append (Product_dic.get (serial_number)) Remain_balance = Remain_balanc E-product_dic.get (Serial_number) [1] Print (shop_list,remain_balance) Continue elif Yes_n        o = = "N": Print (shop_list) Pass continue elif Yes_no = = "Exit": Break Else:print ("Illegal input, please enter Y or n") continueuser_info={}while true:print ("Shopping cart applet: 1, Shopping 2, note Option=input ("Your option>>:"). Strip () if not option.isdigit (): Print ("Input 1 or 2\n ") Continue option=int (option) if option > 2:print (" Input 1 or 2\n ") continue if Opti on = = 1:tag=trUE count=0 While tag:input_user = input ("Your name>>:"). Strip () with open ("User                    . txt ", encoding=" Utf-8 ", mode=" R ") as Read_f:for line in Read_f:line=line.strip (" \ n ") User=line.split (",") [0] Password=line.split (",") [1] balance=line.                        Split (",") [2] if Input_user = = User:user_info.setdefault (user,{})                        User_info[user].setdefault ("Count", 0) user_info[user]["Password"]=password                            user_info[user]["Balance"]=balance if user_info[user]["Count"] >= 3: Print ("%s User lockout"% (Input_user)) Tag=false break El                    Se:print ("{} user does not exist". Format (Input_user)) Continue if Tag: Input_password =Input ("Your password>>:") if Input_password = = user_info[input_user]["Password"]: Print ("{} user password is logged in correctly". Format (Input_user)) print ("User: {}, Balance: {}". Format (user, user_info[user]["Ba (Lance "]))" This is the time to start shopping "Bal                        Ance=int (Balance) shop () Break else: user_info[input_user]["Count"]+=1 print ("{} User Password login error and {} try opportunity". Format (Input_user, 3-user_info[i nput_user]["Count"]))

  

Python program to write shopping applet

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.