Python basic exercises of the cart

Pre-knowledge # 
# the enumerate (the LIST) 
# outputs a tuple, one of the first index, the second element is 

# A = [. 1, 2,. 3,. 4] 
# for I in the enumerate (A): 
# Print (I) 
'' ' 
(0,. 1) 
(. 1, 2) 
(2,. 3) 
(. 3,. 4) 
' '' 
# for I, Item in the enumerate (A): 
# Print (I, Item) 
'' ' 
0. 1 
. 1 2 
2. 3 
. 3. 4 
' '' 
#len (the lIST) returns the length of the list # 

# Print ( '\ 033 [31 is; 1mCONTENT \ 033 [0m')    

# red output the CONTENT 

#exit () method # exit 


===================== # 
#BEGIN 
# 
productList = [ 
    ( 'iPhone', 5000), 
    ( 'Watch', 20000), 
    ( 'Coffee', 1000 ),
    ('pencil', 500),
    ('switch', 2000),
    ('Audi', 200000),
]
purchasedList = []

salary = input('请输入你的工资金额:')
if salary.isdigit():
    salary = int(salary)
    while True:
        for i, item in enumerate(productList):
            print(i, item)

        userChoice = input('要购买东西吗?')
        if userChoice.isdigit():
            userChoice = int(userChoice)
            if userChoice < len(productList) and userChoice >= 0:
                userWantBuy = productList[userChoice]
                if userWantBuy[1] <= salary:
                    purchasedList.append(userWantBuy)
                    print('已添加',userWantBuy[0],'To cart')
                    - the salary = userWantBuy [. 1] 
                else:
                    ( '! you have enough money wow') Print 
            the else: 
                Print ( 'you choose:', userChoice, '! item does not exist') 
        elif userChoice.lower () == 'Q': 
            print ( '======= already purchased =======') 
            for I in purchasedList: 
                Print (I) 
            Print ( 'your balance is: \ 033 [31; 1m { } \ 033 [0m'.format (the salary)) 
            BREAK     
        the else: 
            Print ( 'input error la') 
the else: 
    Print ( '! format does not pay') 
    Exit (-1)

  

Guess you like

Origin www.cnblogs.com/lcxiao/p/11367110.html