Editor

Maximum of Two

#5 · Python Basics · Beginner · 30 XP · about 3 min

Write a function called max_of_two(a, b) that returns the larger of two numbers (without using Python's built-in max() function).

Example

max_of_two(5, 3)   # Returns 5
max_of_two(3, 5)   # Returns 5
max_of_two(7, 7)   # Returns 7
max_of_two(-2, -5) # Returns -2

Requirements

  • Do NOT use the built-in max() function
  • If both numbers are equal, return either one
  • Handle negative numbers correctly

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.