[2] [path of python, Python programming based learning problems] 1

[Duplicate data list, when used for looping through the list, the last taken only once. ]

1  # store list of items 
2 COM = [
 . 3      ( " iPhone " , 5800 ),
 . 4      ( " MacBook " , 9000 ),
 . 5      ( " Coffee " , 320. ),
 . 6      ( " pythonbook " , 80 ),
 . 7      ( " bicyle " , 1500 )
 . 8      ]
 . 9 the shoplist = [] # cart variable 
10  
. 11 the salary = INPUT ( "Please enter your budget: " ) # A total of 5000 changed how much money can choose 
12  IF salary.isdigit (): # Verify 
13      salary = int (salary)
 14      yue = salary
 15  
16      the while yue> = 0: # forming a infinite loop 
. 17  
18 is          for I, V in the enumerate (COM, 1):   # Print product content 
. 19              Print (I, ' > ' , V)
 20 is          comd_num = iNPUT ( " enter the product number (1 ... 5) or exit ( Q): " )     # guide the selection of goods 
21 
22 is          IF comd_num.isdigit ():   # verify the legality of the input 
23 is              comd_num = int (comd_num)
 24              IF comd_num> 0 and comd_num <= len (COM):
 25                  p_com = COM [-comd_num. 1] # selected merchandise elected 
26                  IF p_com [1] < yue:
 27                      yue - = p_com [1] # bought to buckle budget 
28                      shoplist.append (p_com)
 29                      Print ( " cart products have: " , shoplist)
 30                      Print ( " balance also :" , Yue)
 31                  the else :
 32                      Print ( " Cart products have: " , shoplist) # user selected product number, call the judge in commodity prices enough money 
33                      Print ( " your balance is also S%! " % Yue )
 34              the else :
 35                  Print ( " no such goods " )
 36          elif comd_num == " q " :
 37              Print ( " ------------- ------ goods you have purchased as follows -------- " )
 38              for i inthe shoplist:
 39                  IF shoplist.count (I)> = 2 :
 40                      Print (I, " * " , shoplist.count (I))
 41 is                  the else :
 42 is                      Print (I)
 43 is              Print ( " -------- ------ welcome to you next ---------------! " )
 44              BREAK 
45          the else :
 46              Print ( " illegal character " )

Balance = 200 to buy two books, is the result of exit

Enter a product number (1 ... 5) or quit (q): q
------------- -------------- goods you have purchased as follows
( 'pythonbook', 80) * 2
( 'pythonbook', 80) * 2
-------------- always welcome! ---------------

How to become a handling

------------- You have purchased the following goods --------------
( 'pythonbook', 80) * 2
--------- ----- always welcome! ---------------

Guess you like

Origin www.cnblogs.com/watalo/p/11495094.html