Python Forum
HELP! Return Statement Debugging
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP! Return Statement Debugging
#2
To be sure you know the absolute value of n can be found with abs(n).

And the absolute value of 0 is None. It has no value. You can add as many as you want and still 0. Not a math person exactly, but I think absolute value is the measurement of a number from 0 in integers. 5 and -5 are both absolute 5 as they are both 5 whole numbers from 0.

(Jan-27-2020, 05:51 AM)michael1789 Wrote: the print line appeared twice -- and I have no idea how the second print line

Oh, I missed this. You'll note that your second print line is actually the output for the first entry. You are calling main() from with another function, it runs that execution of main() then finishes the first one it started when it drops back out.

This works:
while True:
    def absoluteValue(n):
        if n < 0:
            return -n
        elif n > 0:
            return
        else:
            print("Please key in a value greater or lower than 0 !! ")
            
     
    def main():
        y = input("Key in an integer : ")
        n = int(y)
        print("The Absolute Value of", y, " is ", absoluteValue(n))
     
    main()
Reply


Messages In This Thread
HELP! Return Statement Debugging - by HappyMan - Jan-27-2020, 05:42 AM
RE: HELP! Return Statement Debugging - by michael1789 - Jan-27-2020, 05:51 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,594 Sep-17-2022, 04:03 PM
Last Post: Columbo
  How to invoke a function with return statement in list comprehension? maiya 4 3,050 Jul-17-2021, 04:30 PM
Last Post: maiya
  syntax error on return statement l_butler 5 3,261 May-31-2020, 02:26 PM
Last Post: pyzyx3qwerty
  return statement will not work TheTechRobo 2 2,732 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  Embedding return in a print statement Tapster 3 2,420 Oct-07-2019, 03:10 PM
Last Post: Tapster
  return statement usage SB_J 3 2,525 Jul-16-2019, 07:24 PM
Last Post: snippsat
  I don't understand this return statement 357mag 4 2,894 Jul-10-2019, 07:02 PM
Last Post: perfringo
  Return Statement in Python IDLE editor NMW 10 10,963 Jul-11-2017, 09:47 PM
Last Post: NMW
  Need help understanding return statement python_lover 4 4,524 Mar-03-2017, 10:09 AM
Last Post: python_lover
  Python basics about __init__ and return statement wk14 5 6,216 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