Python
Conditional
statements
Undergraduate degree course
Dr Kazeem Oyebode
PhD Computer Engineering
LEARNING OBJECTIVEs
❖ To explain Python conditional statements such as if and if else.
❖ To implement the for conditional statements in Python
❖ To implement for and while conditional statements.
Python Conditional statements
❖ Python comes with a number of conditional statements that let us direct the
course of your program depending on specific circumstances.
❖ The conditional statements in Python that are most frequently used are :
❖ If statement
❖ If else statement
❖ If elif else statement
❖ While statement
❖ For statements
if statement
❖ if statement: a block of code will be executed if a certain condition is true.
IF statement
If-else statement
❖ if-else statement: This statement is useful when we would like to execute
one block of code if a condition is true, and another block if it is false
If Else Statement - Right password entered
If Else Statement- wrong password entered
Standard Data Types IF ELIF ELSE
❖ if-elif-else statement: This is useful when we have to check multiple
conditions. The elif (short for "else if")
If elif Else Statement
If elif Else Statement
While Statement
❖ The while statement in Python is used to create a loop that repeats a block
of code as long as a specific condition is true.
❖ It enables you to carry out a series of instructions repeatedly until the
condition is met.
While statement
For statement
❖ The for statement is used to iterate over a sequence, such as a list tuple or
list
For statement
For statement
Project
❖ Use a conditional statement of your choice to print out numbers greater
than 15 from the list below
❖ [23,45,1,2,3,4,5,6,7,8,5,7]
Summary
Summary
❖ We have learned Python conditional statements such as if and if
else.
❖ We implemented conditional statements in Python
❖ Finally, we implemented conditional statements such as while
and for statements
FURTHER READING RESOURCES
❖ Python Programming Fundamentals (2nd Edition) by Kent D.
Lee
❖ Python Programming: An Introduction to Computer Science (2nd
Edition) by John Zelle
Thank
You