Copy this title into a new OneNote document:
CT7 – AU – Nested Conditional Sequences
Complete this table and copy it into the OneNote document:
| ⏱️ Do It Now: |
| Answer the following questions (1) Draw the flowchart symbol for data flow (input and output) (2) Draw a flowchart for an algorithm where the user has to correctly input the third planet of the solar system. |
🎯 Objectives:
(1) We will be able to explain the concept of nesting within conditional sequences
(2) We will be able to write code that features nesting
(3) We will be able to create nested sequences based on a description of an algorithm
📖 What is Nesting?
Many (if not most) programs feature multiple decisions being made, based on the outcome of prior decisions.
We call this process “nesting”
If you look at the code below you will see an example of nesting.
# Activity 1 - Example of Nesting
#------------------------------ Global Variables -------------------------------
rain = "" # Initialising an empty string variable called rain
wind = "" # Initialising an empty string variable called wind
#-------------------------------- Main Program ---------------------------------
rain = input("Is it raining? Y or N ")
windy = input("Is it windy? Y or N ")
if rain == "y":
if windy == "y":
print("Wear a rain coat - forget the umbrella!")
else:
print("Bring an umbrealla")
else:
if windy == "y":
print("You might want a hoodie, it could be a bit breezy")
else:
print("Just wear what you want")
✍️ Explanation
(1) Screenshot the code above into your OneNote and explain exactly how the algorithm works.
(2) Explain the concept of nesting, and outline why it is useful for Computer Scientists
⌨️ Activity 2a
(1) Run this program to investigate how it works
(2) Create a flowchart that represents the program
(3) Write the program in Python
(4) Ensure the flowchart and Python code are evidenced in your OneNote
⌨️ Activity 2b (Extension)
(1) Run this program to investigate how it works
(2) Create a flowchart that represents the program
(3) Write the program in Python
(4) Ensure the flowchart and Python code are evidenced in your OneNote
🔎 Plenary Activity
(1) Complete the quiz: Y10 Data Types, Conditionals and Flow Charts Quiz
(2) Screenshot your result into OneNote
(3) For any incorrect answers, explain why you got them wrong