Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print within function
#1
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()
Reply
#2
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Awesome, thank you so much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 314 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  How to print variables in function? samuelbachorik 3 918 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  How to print the output of a defined function bshoushtarian 4 1,321 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Why does absence of print command outputs quotes in function? Mark17 2 1,393 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 1,757 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  output correction using print() function afefDXCTN 3 11,111 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print function output wrong with strings. mposwal 5 3,137 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 2,524 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,500 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Invalid syntax on print function DoctorSmiles 2 2,823 Jul-12-2020, 07:39 PM
Last Post: DoctorSmiles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020