Create a product page that requires
1 , display the commodity name and price correspondence relation
2 , access to user pay level
3 , provide users with the option to buy products function
4 , users purchase finished goods, display user account balance
5, prompt the user whether to continue to purchase
#!/usr/bin/env python //program starts #file: list.py#date: 2016-01-13import sys //Insert module, convenient to call function goods = [' Iphone6 ', ' Quecao ', ' LV ', ' Car '] //Define items and price List contents prices = [5200,80,750,30000]lists = [] //defines an empty list, similar to a shopping cart Wide = 50title = ' Shoplist ' half = (50 - len (title) - 2) // 2 //the variable while true: //exception handling used by the print header requires that the input wage must be an integer try: wage = int (Raw_input ("Hello, please input your wages: ")) break except valueerror: print "please input a number, not String. " while true: print "Look the shoplist, Please input what you want: " print ' = ' * 50 print ' * ' * half + ' ' + title + ' ' + ' * ' * half print '%-25s%25s ' % (' Goods ', ' prices ') print '-' * 50 for p in Goods: print "%-25s%25s" % (P,prices[goods.index (p)]) print ' = ' * 50 //Display Menu Contents Shop = raw_input ("Please input one item to buy:") .strip () if shop == ' quit ': //exit option print " you have bought these things: %s " % lists sys.exit () elif shop in goods: //items in the list &nbsP; pay = prices[goods.index (Shop)] //Fetch Price print "%s, %d" % (Shop,prices[goods.index (shop)) if wage > pay: // when wages are greater than the price wage -= pay //Balance after purchase Lists.append (Shop) //add a purchase to an empty list print "Ok, %s put in list. your wage now left: %d " % (shop,wage) else: if wage < min (prices): //wages greater than the minimum price print "Your money can ' t pay for anything. you have bought these things: %s " % lists &nBsp; sys.exit () Exit Page else: print "Sorry, this %s you can ' t put it, please look other! " % shop else: print "your choice not In goods! " Break
Note : python2.7, practice using!
This article from "Experience from pain" blog, declined reprint!
Python---shopping extensions