Python implements a simple shopping cart system

 
'' 
Shopping cart system 
'' ' 
import sys 

product = [[1,' Patek Philippe ', 4500000], [2,' Maybach ', 4550000], [4,' Gucci ', 165000], [6,' Lancome ', 105000], [5, 'Tiffany', 1075000], 
           [3, ' Thinking', 195000] ] 

salary = int (input ("\ nPlease enter the total amount of credit card:")) 
cart = [] 
# 
while True: 
    for p in product: # Display the list of purchased items 
        print (p) 

    choice = int (input ("\ nPlease enter the purchase number:")) # Enter the purchase code 
    if choice> 0 and choice <= len (product):   # judge The number meets the requirements 
        index = 0 
        for p in product: 
            index = index + 1 #Locate the index 
            if p [0] == choice: #The index is associated with the code 
                print ("The goods purchased this time are:% s "% p)
                salary-= product [index-1] [2] 
                if salary <= 0: 
                    print ('\ 
                    nInsufficient account balance') 
                    salary + = product [index-1] [2] 
                    pass 
                else: cart.append (p) 

    else : 
        print ('\ nplease input correct num, num> 0 and num <% d'% len (product)) # The required number conforms to 
    print ('The product already purchased is:% s, the remaining amount of the account:% d'% (cart , salary)) 
    out = str (input ("\ nIf you leave please enter 'b':")) 
    if out == 'b': 
        sys.exit (0) 
    else: 
        continue
 

 

 

Guess you like

Origin www.cnblogs.com/hqt0731/p/12741887.html