Python Forum

Full Version: Max number of three
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
We don't see the actual assignment, but I really doubt they expect you to just wrap the built-in max() function
(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!!