0

1- I get this error when I try to print a return value from inside main => " name 'conversion' is not defined " 2- I have some dummy prints to debug my code

def main():
    time = input("What time is it? ")
    convert(time)
    **print (conversion)**

def convert(time):
    hours, minutes = time.split(":")
    print("==1== " + f'{hours = }' + f'{minutes = }')
    print("==2== " + f'{hours = }')
    print("==3== Float of hours", float(hours))
    print("==4== Float of minutes", float(minutes))
    conversion = float(hours)+(float(minutes)/60)
    print ("==5== ",f'{conversion = }')
    print ("==6== ", conversion)
    return conversion

if __name__ == "__main__":
    main()

I tried commenting out the print (conversion) inside main. If I do, I get no errors but I am supposed to return a decimal value back to main

0

1 Answer 1

4

Merely calling a function does not automatically retrieve its returned value, as you seem to expect.

You need to assign its returned value to a variable:

def main():
    time = input("What time is it? ")
    conversion = convert(time)
    print (conversion)

And you knew this already, because you did properly assign time to the returned value from input() on the previous line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.