Xiaobai's growth diary day 2 Breaking the program (still own food) 4.26 10; 28'

Requirements:


1. After starting the program, let the user input the salary, and then read the product list.


2. Allow the user to purchase the product according to the product number


.


4 You can exit at any time, when you exit, print the purchased goods and balance

shopping_list=[]
list=[
    ('Iphone',5800),
    ('Mac Pro',9800),
    ('Bike',800),
    ('Watch',10600),
    ('Coffee',31),
    ('Alex Python',120)
]
salary= input ( 'please enter your salary;' )
 if salary.isdigit(): #Generally means that the input is a number
     salary= int (salary ) #Convert to a number
 while True:
         for index,i in enumerate (list): #index is the subscript to loop from the first in the list
 print (index ,i)                
        choose= input ( 'What do you want to buy==>:' )
         if choose .isdigit():
            choose =int(choose)
            if choose <len(list) and choose>=0:
                a=list[choose] # a represents the position of the product to be purchased
 if a[ 1 ]<=salary:    #a[1] represents the price of the product to be purchased a represents the product `1
 salary=salary-a[ 1 ]                                    
                    shopping_list.append(a)
                    print ( 'add %s your shopping_list, and %s salary is left'   %(a,salary))
                 else :
                     print ( 'You still have %s salary left to buy a fart!!!' %salary )
             else :
                 print ( 'product code [%s] is not exist!' %choose )
         elif choose == 'q' :
             print ( '--------shopping list------' )
             for p in shopping_list:
                 print (p)
             print ( 'add %s your shopping_list, and %s salary is left'  %(a,salary))
             exit ()
         else :
             print ( 'bad option' )

else :
     print ( 'Please enter a number:' )



old saying; memorizing words and sentences

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325818012&siteId=291194637