Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is the return function not passing the variables to the next function?

I’m trying to get rid of the error without moving the input function out of the userInput function. I expected the return function to remove the NameError. I looked all over stack exchange and in my textbook to figure out this problem.

def userInput():
    a = float(input("Enter a: "))
    b = float(input("Enter b: "))
    return (a,b)

def printFunction(a2,b2):
    print(a2)
    print(b2)

def main():
    userInput()
    printFunction(a2,b2)
    
main()

NameError: name ‘a2’ is not defined

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Functions return values, not variables. The names a and b are only defined in userInput: you need to receive the values returned by userInput in variables defined in main.

def main():
    x, y = userInput()
    Printfunction(x, y)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading