Python BasicsEasy

Greatest of two numbers

Detailed guide and Python implementation for the 'Greatest of two numbers' problem.

Problem Statement

Easy

Write a function greatest_of_two(a, b) that takes two integers a and b and returns the greater of the two. If both are equal, return that value.

Constraints
  • -10^9 <= a, b <= 10^9

Examples

Example 1
Input
a = 10, b = 20
Output
20
Explanation

20 > 10, so 20 is the greatest.

Example 2
Input
a = 7, b = 3
Output
7
Explanation

7 > 3, so 7 is the greatest.

Example 3
Input
a = 5, b = 5
Output
5
Explanation

Both are equal, so return 5.

Need a Hint?
Consider using Basics-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.