2016-11-10 37 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 

列表的第三个元素