Learning Outcomes:

Upon successful completion of this lesson, you will be able to:


Lesson 1 of 9: Why Decision Control Structure

Programs are executed in sequence, known as sequential control structure. Often, we need to tell the computer to do something only when some conditions occur. This will alter the sequential execution of the program.

Bill Gates explains IF & IF/ELSE statements (about 1 min)


1.png

For example, if the condition "Cold outside" is True, we will wear a jacket before proceeding to the next action.

2.png

The True condition can cause one or more statements to be executed.

Let's look at an example. A program asks the user to enter age and if the age is less than 18, it will display a message "You are too young to drive now". Otherwise, it will display "You are of legal age to drive now".

The flowchart for the example will look like this. Click to show the corresponding Python code.

Flowchart.png


Knowledge Check

A program asks the user to enter age and if the age is less than 0, it will display a message "Invalid Input!". Draw the flowchart.