/    /  Python – If..Else.. Statements

Python – If..Else.. Statements:

In this tutorial, we will discuss about the “if” Condition statement. Let us understand how this “if” statements work. There will be 2 parts in the “if” statement.

They are “if” and “elif”, “else” which is optional. when the “if” condition satisfies then it executes the program inside that else it execute the program inside “elif” or “else” statements.

Syntax:

if Condition:

program of if

elif test expression:

program of elif

else:

program of else

Below is the example of If.. Else:

Example 1:

>> x=int(input("Please enter a number:"))

Please enter a number:10

>>> if x<0:

...     print("negative is zero")

... elif x==1:

...     print("single")

... else:

...     print("positive and greater than 1")

...

positive and greater than 1.

Example 2:

>>> x=int(input("Please enter a number:"))

Please enter a number:1

>>> if x<0:

...     print("negative is zero")

... elif x==1:

...     print("single")

... else:

...     print("positive and greater than 1")

...

Single