15,507,755 members
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

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

## Solution 2

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?

v2

## Solution 1

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?

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