Python Forum
return statement will not work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: return statement will not work (/thread-25440.html)



return statement will not work - TheTechRobo - Mar-30-2020

I have a problem with python 3.x.

I am trying to make a CLI calculator using python 3.x, and tried to use the return statement.

However, even after I use return , it gives me an error that my variables have not been defined.

Does anyone know how to fix this? Here is a snippet of my code:

def getNum(): #ask for two numbers and then return to function
    n1 = int(input("Please enter the first number: "))
    n2 = int(input("Please enter the second number: "))
    return n1, n2
def multi(): #multiplication
    getNum()
    print("\nThat equals...")
    print(n1 * n2)
multi()



RE: return statement will not work - stullis - Mar-30-2020

It is working, but the returned values aren't stored anywhere. Add a couple variables:

def getNum(): #ask for two numbers and then return to function
    n1 = int(input("Please enter the first number: "))
    n2 = int(input("Please enter the second number: "))
    return n1, n2

def multi(): #multiplication
    n1, n2 = getNum()
    print("\nThat equals...")
    print(n1 * n2)

multi()



RE: return statement will not work - TheTechRobo - Mar-30-2020

Thank you so much @stullis!! You are so much help.