不断增加函数中变量的值,我调用它的次数越多

keep increasing the value of a variable in a function the more i call it

如何使变量的最终值是两个用户输入的相加?

def value():
    amt = int(input("enter value: "))

def go_again():
    again = input("DO you want to go again(y/n)")
    if again == "y":
        value()
    else:
        exit()

value()
again()

(这是一个较短的代码,但与我正在处理的类似。)

只需将 value 函数嵌入 go_again 并将其 运行 嵌入 while 循环:

def value():
    return int(input("enter value: "))

def go_again():
    val = value()
    while input("DO you want to go again(y/n)") == "y":
        val += value()
    exit()


go_again()