Learning Outcomes:
Upon successful completion of this lesson, you will be able to:
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)
For example, if the condition "Cold outside" is True, we will wear a jacket before proceeding to the next action.
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.
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.