-1

I am just testing a function however the function returns nothing. I can't quite understand the rules. New to programming.

What I've tried:

Def func0(x, y):
    if x < y:
        z = (x*y) - x 
        return z
    else:
        w = (y*y) - 1
        return w

This returns nothing when called.

For example I'm expecting if I call the function: func0(5,6) For it to return 25

Is there a better way to achieve or write this?

Thank you

  • `Def` should be `def`. – Barmar Feb 09 '23 at 23:48
  • 2
    When I correct that it works. `print(func0(5, 6))` prints 25. – Barmar Feb 09 '23 at 23:49
  • 2
    Did you remember to print what it returns? – Barmar Feb 09 '23 at 23:49
  • When I try your code (after fixing the typo - I assume this is due to phone autocorrect), the code works, and returns as you expect it to. I added some duplicate questions for the underlying background material, in case you have some wrong expectations about **what it means to return something**. – Karl Knechtel Feb 10 '23 at 01:14

1 Answers1

0

I'm expecting if I call the function: func0(5,6) For it to return 25

If you just call the function like that, then it does return the value, but you aren't doing anything with the returned value, so it appears like nothing was returned.

You need to call it like this which saves the returned value in a variable:

myresult = func0(5,6)

And then you could do something with myresult, like print it.

John Gordon
  • 29,573
  • 7
  • 33
  • 58