Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Max number of three RavCOder Not Blown Up Yet Posts: 69 Threads: 19 Joined: Sep 2019 Reputation: 0 Likes received: 1 #1 Oct-09-2019, 07:28 AM 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 perfringo Da Bishop Posts: 1,139 Threads: 5 Joined: Jun 2018 Reputation: 117 Likes received: 256 #2 Oct-09-2019, 07:35 AM (This post was last modified: Oct-09-2019, 07:35 AM by perfringo. Edited 1 time in total.) 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. buran Posts: 4,796 Threads: 86 Joined: Sep 2016 Reputation: 324 Likes received: 1045 #3 Oct-09-2019, 07:49 AM We don't see the actual assignment, but I really doubt they expect you to just wrap the built-in `max()` function RavCOder Not Blown Up Yet Posts: 69 Threads: 19 Joined: Sep 2019 Reputation: 0 Likes received: 1 #4 Oct-09-2019, 08:03 AM (This post was last modified: Oct-09-2019, 08:05 AM by RavCOder.) (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!! « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)