Python Ch2
Python Ch2
if condition:
#block of statements
else:
#another block of statements (else-block)
Output:
Enter your age:- 90
You are eligible to vote !!
Ashika Pokiya Dept. of Computer Engineering LJ
Conditional Statements
If-elif-else statement
The elif statement enables us to check multiple
conditions and execute the specific block of statements
depending upon the true condition among them. We
can have any number of elif statements in our program
depending upon our need. However, using elif is
optional.
if expression 1:
# block of statements
elif expression 2:
# block of statements
elif expression 3:
# block of statements
else:
# block of statements
Ashika Pokiya Dept. of Computer Engineering LJ
Conditional Statements
If-elif-else statement
Example:
number = int(input("Enter the number:- "))
if number==10:
print("number is equals to 10")
elif number==50:
print("number is equal to 50");
elif number==100:
print("number is equal to 100");
else:
print("number is not equal to 10, 50 or 100");
Output:
Enter the number:- 15
number is not equal to 10, 50 or 100
Ashika Pokiya Dept. of Computer Engineering LJ
Conditional Statements
Nested-If statement
Python while loop is just another Python
statement. As you already know that while loop body
can contain statements.
we can write while loop inside while loop. While
loop inside another while loop is called Nested While
Loop.
Syntex:-
#statement(s)
while condition_1 :
#statement(s)
while condition_2 :
#statement(s)
Ashika Pokiya Dept. of Computer Engineering LJ
Conditional Statements
Nested-If statement
Example:
i=1 Output:
while i <= 4 : 1111
j=0 2222
while j <= 3 : 3333
print(i, end=" ") 4444
j += 1
print()
i += 1