First, the Python shopping process script
More than half a month of Python study, spent a day to finally write a simple shopping process script, but also a summary of Python and knowledge of the review, I am very dishes, scripts are very general.
#!/usr/bin/env python# descript message# author:allentuns# mailbox:[email Protected]# tel:13260071987import startupimport sysimport osuserfile = open (" User.txt "," R ") Rss = userfile.read () while true: User = raw_input ("Please your name:") if len (user) == 0: print "Empty user,try again." continue elif user in rss: break elif user == "q" or user == "quit" or user == "Exit": print "Welcome to come again next time" sys.exit () else: print "%s is not exists,please try again input your name " % (user) continuewhile True: Passwdd = raw_input ("Please your password:") if len (PASSWDD) == 0: print "SoRry , input your password error , please try again. " elif passwdd in rss: print "\ n" + "Welcome to %s login shoppings: " % (user) break else: print " Password is error,please try again. " while true: try: salary = int (Raw_input ("Please input your salary: ")) break except ValueError: print "please input a number,not string. " File = open (' Shoplist.txt ', ' R ') for fr in file: fr = fr.rstrip () print frfile.close ( ) print "" "Options and arguments: input "D" : Delete from shoplist into del input "F" : Return to the total pages input "T" : total shoplist "" "products = [" Apple ', ' Iphone ', ' Bike ', ' Sansung ', ' Piano ', ' coffer ']prices = [ 13500, 4500, 490, 2900, 1900, 35 ]list00 = []while True: choose = raw_input ("Please choose your buy things: ") if choose in products: product_num = Products.index (choose) product_price = prices[product_num] if salary > product_price: print "%s $%d" % ( Choose,product_price) list00.append (choose) print "Add %s into your shoplist" % (choose) print "You choose to purchase the commodity list:",list00 salary = salary - product_price else: if salary < min (Prices): print "Sorry , reset of your salary cannot buy anythings." sys.exit () elif choose == "T": print "salary left :$%s" % ( Salary) Sys.exit () elif choose == "D": while True: delchoose = raw_input ("your will things remove from into shoplist:") if delchoose in products: product_num2 = products.index (Delchoose) product_price2 = prices[product_num2] salary = salary + product_price2 list00.remove (delchoose) print list00 print salary break
This script can achieve the implementation of the function: 1, through the user name and password authentication to log on to the shopping system, no one refused. 2, after the approval, the user needs to enter the salary will print a shopping list, list of items that can be purchased. 3, the user can use their own wages to buy items in the shopping list, provided that the wages from the beginning of the bear, if not afford to quit. 4. Purchased items can be added to the shopping cart or deleted from the shopping cart. 5, determine the purchase of goods after the end, you can settle the total amount of purchases of items, and then exit the whole system the disadvantages of this script are many: 1, the user authentication problem 2, write script comparison verbose 3 、....
Second, the script test
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/CB/wKiom1RZ2vfBlH8ZAAOEPOgHd0o005.jpg "title=" 1.png " alt= "Wkiom1rz2vfblh8zaaoepoghd0o005.jpg"/>
This article is from the "Zheng" blog, make sure to keep this source http://467754239.blog.51cto.com/4878013/1572203
Python Shopping Process Script