Python-5
Python-5
Python Conditional
Statements
z
1. Conditional
Statements
2. Loop Statements
3. Branching Statements
z
1. If Statement
2. Switch Statement
Example:
a=100
b=900
if (a>b):
print(“A is Big Number”)
z
2. Run a block of statements when a condition is
true, otherwise, run another block of statements
EXAMPLE:
a=100
b=900
if (a>b):
print(“A is Big Number”)
else:
print(“B is Big Number”)
z
True or False
10 > 20
10.234 > 10345
“Philippines” > “China”
z
EXAMPLE:
a=”Philippines”
b=”China”
if (a>b):
print(“Philippines is Big”)
else:
print(“China is Big”)
z
3. Run a block of statements when a
compound condition is true
EXAMPLE:
a=100
b=90
c=80
if ((a>b) and (a>c)):
print (“A is Big Number”)
z
3. Run a block of statements when a
compound condition is true
EXAMPLE:
a, b, c = 100, 90, 80
if ((a>b) and (a>c)):
print (“A is Big Number”)
z
4. Run a block of statements when a compound
condition is true, otherwise run another block of
statements
a=100
b=90
c=800
d=70
a=100
b=90
c=800
d=70
else:
Statement(s)
elif (condition):
Statement(s)
elif (condition):
Statement(s)
else:
Statement((s)
z Example:
a=0
elif (a>10000):
else:
syntax:
if (condition){
if (condition){
if (condition){
Statements
z
5. Execute a block of Statements when
more than one condition is true (Nested if)
syntax:
if (condition){
if (condition){
if (condition){
Statements
z
5. Execute a block of Statements when
more than one condition is true (Nested if)
a=100
b=90
c=70
d=50
z
Problem: Find the biggest variable (Integer variables)
among 4 variables
Use Compound Condition and else if…
print (“__________”)
print (“___________”)
print (“___________”)
else:
print (“_____________”)
z
Problem: Find the biggest variable (Integer variables)
among 4 variables
Use Compound Condition and else if…
else: