Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Check Even or OddE02. Determine Positive, Negative, or ZeroE03. Compare Two NumbersE

Problem No 3

Compare Two Numbers

Easy

10 minute session

Summary

Compare two numbers and report whether the first is greater, less, or equal to the second.

Problem statement

Create a function compare_numbers(a, b) which compares two numeric values a and b and returns: - 'greater' if a > b - 'less' if a < b - 'equal' if a == b Use conditional statements to return the correct string.

Task

Implement compare_numbers(a, b) that returns 'greater', 'less', or 'equal' depending on the comparison.

Examples

Example 1

Input

a = 3, b = 5

Output

less

Explanation

3 is less than 5, so the function returns 'less'.

Input format

Two numbers a and b (integers).

Output format

A string: 'greater', 'less', or 'equal'.

Constraints

a and b are integers; values may be negative or large.

Samples

Sample input 0

2, 1

Sample output 0

greater

Explanation 0

2 > 1.

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.

12:40 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.