Category Archives: Decision Making

Decision Making – Python

The if… statement :-
The if..statement performs an indicated action only when the condition is true;otherwise action is skipped.
syntax is :

if expression:
statement(s)

in python if expression is non-zero and non-null values,it is assumed as True & if it is either zero or null  then it is assumed as false value.

The if…else statement :-
The if…else statement allows you to specify that different action are to be performed when the condition is true than when the condition is false.

if expression:
statement(s)
else:
statement(s)

The if…elif statements :-
This is nested statement for multiple cases by placing if…elif statements inside if….else statements.

if expression:
statement(s)
elif expression:
statement(s)
else:
statement(s)

For instance :- 

animal = input("Enter animal name :-")
if animal == "fish":
print ("animal is fish")
print("Go fast ! catch it ")
elif animal == "frog":
print("Don't catch it.")
else:
print("animal is not fish and frog..")
print("run away it may be dangerous....")
input("Press Enter..")

Output :-
Untitled