Python Forum

Full Version: print within function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am writing a simple converter to change a bearing to a polar coordinate. I'm not quite sure what I'm doing wrong, but the code below won't print the value of the conversion before moving to anotherPolar():

def polar():
    direction = input("North or South?")
    angle = input("Angle from N Or S:")
    secondary = input("East or West?")
    polarangle = 0
    if direction == 'N' or direction == 'North':
        if secondary == 'E' or secondary == 'East':
            polarangle = round(90 - float(angle),4)
            return polarangle
        elif secondary == 'W' or secondary == 'West':
            polarangle = round(90 + float(angle),4)
            return polarangle
    elif direction == 'S'or direction == 'South':
        if secondary == 'E' or secondary == 'East':
            polarangle = round(270 + float(angle),4)
            return polarangle
        elif secondary == 'W' or secondary == 'West':
            polarangle = round(270 - float(angle),4)
            return polarangle
    print(polarangle)

polar()

def anotherPolar(): 
    again = input("Another?:")
    if again.lower() == "y" or again.lower() == "yes":
        polar()
        anotherPolar()
    elif again.lower() == "n" or again.lower() == "no":
        print("Goodbye")
    else:
        print("Invalid Entry")
        anotherPolar()

anotherPolar()
Hello! In polar() definition if the first if is passed the nested if statements have return statement. So if return is executed the function is not working enymore and the last line with the print(powarangle) doesn't execute.
Awesome, thank you so much!