2016-11-10 65 views
0

我想獲取用戶輸入(一個整數)並使用它將列表中的第三個參數相乘。我不知道如何去用這個代碼目前我有:Python爲txt文件中的每行打印語句

def add_cart(): 
    cart_YorN = "" 
    while cart_YorN not in ("y", "n"): 
     cart_YorN = input("\nWould you like to add this item to your cart? ") 
     if cart_YorN == "y": 
      multiply = int(input("Okay, how many of this item would you like? \n")) #multiply is the variable that will carry the multiplication value 
      receipt_list.#????? #not sure what to do here 

receipt.list是包含3個參數列表,我想第三個通過「乘」相乘。 此外,一旦這個已經相乘,這將更新列表?

回答

1
result = receipt_list[2] * multiply 
+0

爲什麼這項工作進行更新? – ppperry

+1

因爲這是python ... – nrhode

0

我認爲你可以使用:

receipt_list[2] *= multiply 

列表的第三個元素