Python Forum
HELP! Return Statement Debugging
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP! Return Statement Debugging
#1
Dear All
I am a beginner to Python. I wrote the code below but does not understand why when I key in "0" and then a negative number (says "-5"), the print line appeared twice -- and I have no idea how the second print line (ie. "The Absolute Value of 0 is None" come into the picture. Please help.

def absoluteValue(n):
    if n < 0:
        return -n
    elif n > 0:
        return
    else:
        print("Please key in a value greater or lower than 0 !!\t ")
        main()

def main():
    y = input("Key in an integer : \t")
    n = int(y)
    print("The Absolute Value of", y, " is ", absoluteValue(n))

main()
Result :
Key in an integer : 0
Please key in a value greater or lower than 0 !!
Key in an integer : -5
The Absolute Value of -5 is 5
The Absolute Value of 0 is None

LOL LOL LOL
Reply


Messages In This Thread
HELP! Return Statement Debugging - by HappyMan - Jan-27-2020, 05:42 AM
RE: HELP! Return Statement Debugging - by perfringo - Jan-27-2020, 08:19 AM
RE: HELP! Return Statement Debugging - by buran - Jan-27-2020, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with Return statement Columbo 13 2,448 Sep-17-2022, 04:03 PM
Last Post: Columbo
  How to invoke a function with return statement in list comprehension? maiya 4 2,947 Jul-17-2021, 04:30 PM
Last Post: maiya
  syntax error on return statement l_butler 5 3,190 May-31-2020, 02:26 PM
Last Post: pyzyx3qwerty
  return statement will not work TheTechRobo 2 2,680 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  Embedding return in a print statement Tapster 3 2,343 Oct-07-2019, 03:10 PM
Last Post: Tapster
  return statement usage SB_J 3 2,479 Jul-16-2019, 07:24 PM
Last Post: snippsat
  I don't understand this return statement 357mag 4 2,822 Jul-10-2019, 07:02 PM
Last Post: perfringo
  Return Statement in Python IDLE editor NMW 10 10,757 Jul-11-2017, 09:47 PM
Last Post: NMW
  Need help understanding return statement python_lover 4 4,462 Mar-03-2017, 10:09 AM
Last Post: python_lover
  Python basics about __init__ and return statement wk14 5 6,076 Oct-25-2016, 04:31 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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