Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 4

Find Maximum of Two

Easy

6 minute session

Summary

Return the larger of two numbers (int or float). If they are equal, return that value.

Problem statement

Write a function find_max(a, b) that takes two numbers (integers or floats) and returns the larger value. If both numbers are equal, return that value. Use conditional logic (if/else) to compare the two values. Do not use built-in functions like max() in your implementation.

Task

Implement a function find_max(a, b) that returns the greater of the two numeric inputs.

Examples

Simple comparison

Input

find_max(2, 5)

Output

5

Explanation

5 is greater than 2, so the function returns 5.

Input format

Two numbers a and b are provided as function arguments: find_max(a, b).

Output format

Return the larger number (int or float).

Constraints

Inputs a and b are numbers (int or float). You may assume both inputs are valid numbers. Don't use built-in max() for the core logic.

Samples

Sample input 0

find_max(-3, -7)

Sample output 0

-3

Explanation 0

Between -3 and -7, -3 is greater.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

04:57 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.