The fifteenth day of learning python [cart]

# Shopping cart applet: 
idea:
create a list
showing the list
Enter the amount to save money
to create a cart
to take list position value
input number to make a purchase
to the appropriate value assigned cart
How much can determine the remaining purchase the product
type Q to exit
show shopping list and balance!

# __Author: "hanhankeji" 
# DATE: 2019/12/4 

# cart applet: 
    # establish a list, create a list of goods 
jiamubiao = [ 
    ( " mac " , 9000 ), 
    ( " the Kindle " , 800 ), 
    ( " Tesla " , 90000 ), 
    ( " Python Book " , 80 ), 
    ( " Bike " , 200 is ), 
] 
Saving = INPUT ( " Please your Saving Money >>> INPUT: ")
shopping_car  = []
 IF saving.isdigit (): 
    Saving = int (Saving)
     # for I in jiamubiao: a list of connected loop back #for 
    #      Print (jiamubiao.index (I) +. 1, I) do not take the ID table # a value of 0 + 1, and then take the value inside, out of the cycle 
    the while True:
         for i, v in the enumerate (jiamubiao, 1): # products list 
            Print ( " number: " , i, v)   # products Listing 
        # user input product Code: 
        choice = the iNPUT ( " Please select number purchase [exit input: q]: " )
         IF choice.isdigit (): 
            choice= Int (Choice)
             IF Choice> 0 and Choice <= len (jiamubiao): 
                p_item = jiamubiao [-Choice. 1 ]
                 IF p_item [. 1] < Saving: 
                    Saving - p_item = [. 1 ] 
                    shopping_car.append (p_item) 
                the else :
                     Print ( " insufficient balance remaining S%! " % Saving)
                 Print (p_item)
             the else :
                 Print ( " encoding make sure that does not exist!! " )
         elif Choice == " q " :
             Print ( " You have to buy the following commodities " )
             for i in shopping_car:
                 Print (i)
             Print ( " !% s dollars you have left " % Saving)
             BREAK 
        the else :
             Print ( " invalid the INPUT " )

Enter 123456 Results:


3 Insufficient funds! Left 200 is 
( 'Tesla', 90000) 
Reference: 1 ( 'mac', 9000 ) 
Reference: 2 ( 'kindle', 800 ) ) 
ID: 3 ( 'tesla', 90000 ) 
Reference: 4 ( 'python book', 80) 
number: 5 ( 'bike', 200 ) 
Please select Number purchasable items [Exit input : q]: 6 
encoding absence! please confirm! 
ID: 1 ( 'mac', 9000 ) 
ID: 2 ( 'kindle', 800 ) 
ID: 3 ( 'tesla', 90000 ) 
Reference: 4 ( 'python book', 80) 
number: 5 ( 'bike', 200 ) 
Please select number purchase [exit input: q]: q 
you have purchased the following products 
( 'mac', 9000) 
( 'the Kindle', 800) 
you left 200 yuan! 

Process has ended, an exit code of 0

  

Guess you like

Origin www.cnblogs.com/hanhankeji/p/11981419.html