我想获取用户的输入(整数)并使用它来乘以列表中的第3个参数。我不知道如何用我目前的代码来解决这个问题:
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个参数的列表,我希望第三个参数乘以“multiply”。 此外,一旦这个成倍增加,这会更新列表吗?
答案 0 :(得分:1)
result = receipt_list[2] * multiply
答案 1 :(得分:0)
我认为你可以使用:
receipt_list[2] *= multiply
列表的第三个元素将会更新