Editor

Find Maximum

Lists · Beginner · 45 XP · about 5 min

Write a function called find_max(numbers) that returns the largest number in a list.

Challenge: Try to solve this without using Python's built-in max() function!

Example

find_max([1, 5, 3, 9, 2])   # Returns 9
find_max([-1, -5, -3])      # Returns -1
find_max([42])              # Returns 42

Requirements

  • Return the maximum value
  • Handle negative numbers
  • You can assume the list is not empty
def find_max(numbers):
# Your code here - try without using max()!
pass
# Test your function
print(find_max([1, 5, 3, 9, 2]))
print(find_max([-1, -5, -3]))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.