Python Forum
Max number of three - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Max number of three (/thread-21666.html)



Max number of three - RavCOder - Oct-09-2019

Hi,
In this function that I defined, it does not return to the maximum number of three, but return None.
I used * args to see how it worked and I saw what it took for when there are many topics to put and I used max to set the maximum value.
I think the problem is just * args and I wanted to know if there is a way to keep * args without adding arguments.


This exercise took it from the Github repository "46 Simple Python Exercises" and this is the exercise:
Quote:Define a function max_of_three() that takes three numbers as arguments and returns the largest of them.

def max_of_three(*args):
  print(max(args))


if __name__ == "__main__":
  x = int(input())
  y = int(input())
  z = int(input())

  print("The largest number is:",max_of_three(x,y,z))
Regards,
RavCoder


RE: Max number of three - perfringo - Oct-09-2019

If you are not returning (or yield) anything from function it returns None. As you are not returning anything from max_of_three you get None.

As assignment states - you should return maximum of three, so return max(args) should be in compliance with assignment.


RE: Max number of three - buran - Oct-09-2019

We don't see the actual assignment, but I really doubt they expect you to just wrap the built-in max() function


RE: Max number of three - RavCOder - Oct-09-2019

(Oct-09-2019, 07:49 AM)buran Wrote: We don't see the actual assignment, but I really doubt they expect you to just wrap the built-in max() function

I know you don't have to use max (), but I used it because I wanted to see how it worked.

(Oct-09-2019, 07:35 AM)perfringo Wrote: If you are not returning (or yield) anything from function it returns None. As you are not returning anything from max_of_three you get None. As assignment states - you should return maximum of three, so return max(args) should be in compliance with assignment.

Thanks it works now!!