Nested If Statement Example Program


Check the number is positive,negative and also it even or odd using nested if in python

This code prompts the user to input a number and then checks if the number is greater than 0. If it is, the code checks if the number is even or odd. If the number is even, it prints "The given number is positive and also even number", if the number is odd, it prints "The given number is positive and also odd number". If the number is not greater than 0, the code checks if the number is equal to 0, if it is, it prints "The given number is neutral". If the number is not greater than 0 and not equal to 0, it prints "The given number is negative".

Source Code

a = int(input("Enter the number : "))

if(a>0):
    if(a % 2 == 0):
        print("The given number is positive and also even number")
    else:
        print("The given number is positive and also odd number")
elif(a == 0):
    print("The given number is neutral")
else:
    print("The given number is negative")
To download raw file Click Here

Output

Enter the number : 4
The given number is positive and also even number