Working with If Statements
Welcome to the Working with If Statements Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.
Already have an account? Sign In »

Introduction
Welcome to the Working with If Statements Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.
Learning Outcomes
In this module, you will complete the following exercise:
- Exercise 1 - Working with Decision Making Statements
After completing this lab, you will be able to:
- Use the if-else and nested if-else statements in Python programs
Exam Objectives
The following exam objectives are covered in this lab:
- 2.1 Construct and analyze code segments that use branching statements
Lab Duration
It will take approximately 20 minutes to complete this lab.
Exercise 1 - Working with Decision Making Statements
Decision-making is an important aspect of any programming language. You can implement decision-making in Python programs by using the conditional or decision-making statements such as if-else and nested if-else. Based on the conditions specified, the decision-making statements decide the flow of the program.
You can specify a condition using the if-else statement in the program. The condition can return either a true or a false value. If the value is true, a certain set of statements following the ‘if’ statement is executed. If the value is false, the set of statements following the ‘else’ statement is executed. The else statement is optional in an if-else block. You can have only one else statement for each if statement.
The syntax of if-else statement is as follows:
if
else:
You can have an elif statement within an if-else statement block. The elif statement helps to include multiple check conditions. This statement is optional. You can also have multiple elif statements in an if-else block.
The syntax of elif statement is as follows:
if
elif
else:
You can specify multiple conditions using nested if-else statements. You can embed a set of if-else statements within another set of if-else statements. It is recommended to include indentation while writing nested if-else statements for better clarity and understanding.
The syntax of nested if-else statement is as follows:
if
if
else:
else:
In this exercise, you will learn to use the if-else and nested if-else statements in Python programs. In the first task, you will write a program using the if-else and elif statements. In the second task, you will write a program using the nested if-else statements.
Learning Outcomes
After completing this exercise, you will be able to:
- Use the if-else and nested if-else statements in Python programs
See the full benefits of our immersive learning experience with interactive courses and guided career paths.