Lesson guide
What this Python exercise practices
Compare Two Numbers is a beginner practice lesson that focuses on python practice, coding exercises, test feedback. It is designed to be solved in about 10 minutes with examples, starter code, and test feedback.
Prerequisites
- Python basics
- Variables
- Reading simple prompts
Difficulty and time
- Level
- Beginner
- Estimated time
- 10 minutes
Practice path
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.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.