if Statement in Python

Simple if Statement

Simple if is the simplest of all decision making statements. Condition should be in the form of relational or logical expression.


if <condition>:

In the above syntax if the condition is true statements - block 1 will be executed.


# Program to check the age and print whether eligible for voting
x=int (input("Enter your age :"))
if x>=18:
print ("You are eligible for voting")

Output 1:

Enter your age :34

You are eligible for voting

Output 2:

Enter your age :16


As you can see in the second execution no output will be printed, only the Python prompt will be displayed because the program does not check the alternative process when the condition is failed.

Python : If Statement in Python Program List

Program [1]

Write a program that returns True if the input number is an even number, False otherwise.

View Solution