簡體   English   中英

Python為txt文件中的每一行打印語句

[英]Python prints statement for each line in txt file

我想接受用戶的輸入(一個整數),並使用它來乘以列表中的第三個參數。 我不知道該如何處理我當前使用的代碼:

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

receive.list是包含3個參數的列表,我希望將第三個參數乘以“乘”。 另外,一旦倍增,是否會更新列表?

result = receipt_list[2] * multiply

我認為您可以使用:

receipt_list[2] *= multiply

列表的第三個元素將被更新

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM