Aina Emmanuel
Aina Emmanuel

Reputation: 25

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

How can I make the final value of the variable be the addition of the two user inputs?

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()

(This is a shorter code but similar to what I am working on.)

Upvotes: 1

Views: 495

Answers (1)

hardhypochondria
hardhypochondria

Reputation: 388

Just embed value function in go_again and run it in while loop:

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()

Upvotes: 1

Related Questions