Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Max number of three
#1
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
Reply
#2
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
We don't see the actual assignment, but I really doubt they expect you to just wrap the built-in max() function
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(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!!
Reply


Forum Jump:

User Panel Messages

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