Check if a number is positive

EasyIf-Else Programs · 19 of 64

Write a Python program to check whether a number is positive and print True or False.

Advertisement
Input
20, -5, 0
Output
20 True
-5 False
0 False

Approach

  1. A positive number is greater than 0; the comparison itself gives True or False.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs