Python Practice › If-Else Programs › Program 43
Check if two numbers are equal
Write a Python program to check whether two numbers are equal.
Input
(26, 88), (5, 5.0)
Output
26 88 -> the numbers are not equal 5 5.0 -> the numbers are equal
Approach
- Use
==.
Solution
for a, b in [(26, 88), (5, 5.0)]: if a == b: print(a, b, "-> the numbers are equal") else: print(a, b, "-> the numbers are not equal")Output
26 88 -> the numbers are not equal 5 5.0 -> the numbers are equal
Line by line
Line 2
5 == 5.0 is True because the values are equal even though the types differ.
Learn the concept
New to this topic? Read the lesson, then come back.