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.

Syntax:

if <condition>:
statements-block1

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

Example

# 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


Program [2]

Write a python program to print larger number using swap


View Solution


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad