Click here to Skip to main content
15,507,755 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python

1 def find_max(nums):
2 max_num = float("-inf") # smaller than all other numbers
3 for num in nums:
4 if num > max_num:
5 # (Fill in the missing line here)
6 return max_num

Select an answer

a.num = max_num
b.max_num += 1
c.max_num = num
d.max_num += num

What I have tried:

i tried getting a solution to it after working through www.w3schools.com
Posted
Updated 5-Apr-22 2:49am

With 4 possible answers even an experimental brute force approach would work.
The function should return the maximum number.
Now, if the current maximum max_num is smaller than num is it still the maximum? Should it be updated?
Which is a good candidate for updating it?
 
Share this answer
 
v2
Quote:
i tried getting a solution to it after working through www.w3schools.com
How about doing what you are supposed to do, and actually think about the problem. If the current number is greater than the existing maximum then how would you remember it for the next time round the loop?
 
Share this answer
 
Comments
CPallini 5-Apr-22 7:50am    
5.Questions like this one... Computer Science at its best! :-D
Richard MacCutchan 5-Apr-22 7:52am    
lol

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900