Python Practice › If-Else Programs › Program 19
Check if a number is positive
Write a Python program to check whether a number is positive and print True or False.
Input
20, -5, 0
Output
20 True -5 False 0 False
Approach
- A positive number is greater than 0; the comparison itself gives True or False.
Solution
for n in [20, -5, 0]: if n > 0: print(n, True) else: print(n, False)Output
20 True -5 False 0 False
Line by line
Line 2
0 is neither positive nor negative, so it prints False.
Tip
print(n > 0) gives the same result without an if-else.
Learn the concept
New to this topic? Read the lesson, then come back.