Tutorialspoint
Problem
Solution
Submissions

Find the Greatest of Three Numbers

Certification: Basic Level Accuracy: 69.49% Submissions: 118 Points: 5

Write a Python program that finds the largest among three given numbers.

Example 1
  • Input: numbers = [10, 20, 30]
  • Output: 30
  • Explanation:
    • Step 1: Take three numbers 10, 20, and 30 as input.
    • Step 2: Compare the numbers to find the largest.
    • Step 3: 30 is greater than both 10 and 20, so return 30.
Example 2
  • Input: numbers = [-5, -2, -10]
  • Output: -2
  • Explanation:
    • Step 1: Take three numbers -5, -2, and -10 as input.
    • Step 2: Compare the numbers to find the largest.
    • Step 3: -2 is greater than both -5 and -10, so return -2.
Constraints
  • -10^9 ≤ numbers ≤ 10^9
  • Time Complexity: O(1)
  • Space Complexity: O(1)
Functions / MethodsBooleanListGoogleTutorialspoint
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use nested if-else statements: if a > b and a > c: return a
  • Use the max() function: max(a, b, c)
  • Use sorted list: sorted([a, b, c])[-1]
  • Use ternary operator: max_ab = a if a > b else b; return max_ab if max_ab > c else c

The following are the steps to Find the Greatest of Three Numbers:

 1. Take three numbers as input. 
 2. Use conditional statements (`if-elif-else`) to compare them.
 3. Store the largest value in a variable.
 4. Print the largest number.
 5. Verify with different inputs, including equal numbers.

Submitted Code :