Page 114 - 2611_SmartGPT Pro V(5.0) C-7
P. 114
Output
Enter a Number: 12
Number entered is an even number.
Enter a Number: 7
Number entered is an odd number.
This program takes an input Num as an integer, divides it by 2 and compares the remainder with
0. If it is found equal, the number is even, otherwise the program prints that the number is odd.
NESTED IF STATEMENT
The nested if structure allows you to place one if statement inside another. This means the program
first checks a main condition and if that condition is true, it checks another condition within it.
Program 5. To check if a number is positive or negative and, if so, check whether it is even or odd.
Program5.py
File Edit Format Run Options Window Help
num = int(input("Enter a number: "))
if num > 0:
print("You have entered a positive number.")
if num % 2 == 0:
print("Even")
else:
print("Odd")
else:
print("You have entered a negative number.")
if num % 2 == 0:
print("Even")
else:
print("Odd")
Output
Enter a number:9
You have entered a positive number.
Odd
Enter a number:-4
You have entered a negative number.
Even
112 Computer Science (V5.0)-VII

