Introduction
Booleans are a common type in Python. Their value can only ever be one of two things: true or false. Understanding how to use Boolean values is critical, because you need them to write conditional logic.
Scenario: Print warning messages
Suppose you're creating a program that identifies if a piece of space debris is a danger to a spacecraft. If the object is larger than a specified size and will come within range of the spacecraft, a maneuver needs to be performed to avoid a collision. Otherwise, the spacecraft can stay on course.
In this module, you'll use Boolean keywords and operators to write several types of conditional expressions, and determine the spacecraft's reaction.
What will you learn?
By the end of this module, you'll be able to:
- Run code under various conditions by using
if
,else
, andelif
statements. - Combine conditional logic and create more complex conditions by using
and
andor
operators.
What is the main objective?
This module teaches you how to use conditional logic to create decision-driven programs.
Prerequisites
You should be familiar with the concept of programming.
You don't need to install Python to complete this module. You'll use an interactive sandbox to complete the exercises.
If you want to try out the code in the explanations, you might want to work through Get started with Python in Visual Studio Code first, if you haven't already. This module helps you prepare a Python environment.