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.

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 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 Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz