Computing Key Stage 3 Lesson COMy9u5L1
Computing Key Stage 3 Lesson COMy9u5L1
Lesson 1: Warm up
Rebecca Franks
Materials from the Teach Computing Curriculum created by the National Centre for Computing Education
1
How long until the weekend?
2
Syntax checklist Error message support
If you are faced with an error message, read it carefully and try to fix the problem.
3
Task 1 How long until the weekend?
Step 1
Remember: The program uses an integer for each day of the week, ranging from 0 for Monday
to 6 for Sunday. Here’s a handy reference:
0 1 2 3 4 5 6
4
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Task 1 How long until the weekend?
Step 2
Complete line 5, so that the value of remaining is the number of days left until the weekend
(including the current day).
Tip: The current day is an integer, ranging from 0 to 4 in the case of weekdays. Saturday is day 5.
Step 3
Insert the line below in your program, wherever you believe it is appropriate to display the value
of remaining days to the user.
print(remaining, "days until the weekend")
Tip: Make sure this message is displayed only in the case that the day is a weekday.
5
Task 1 How long until the weekend?
6
Task 1 How long until the weekend?
Step 4
Extend the program so that Friday (day 4) is treated differently, with a different message
displayed than for the rest of the weekdays.
Tip: You will need to use if-elif-else, since there will now be three branches in your program.
Example input and output for this can be seen on the next slide.
7
Task 1 How long until the weekend?
8
Explorer Task (Optional task)
Instead of asking the user to type the current day of the week, the program can retrieve the
actual day, using the datetime module.
Replace the lines that receive user input (marked with -) with the lines that retrieve the current
day of the week (marked with +).
9
As seasons roll on by
10
Worked Example 1
This program accesses a list called days, which contains the names of days, to display two
specific items (those with index 5 and 6).
11
Worked Example 2 .
This program accesses a list called days, which contains the names of days, to display the name
of the current day and the day before that.
12
Task 1 Summer
Step 1
13
Task 1 Summer
Step 2
Complete lines 7, 8, and 9 with an integer, so that the program displays the names of the
summer months.
Tip: You are used to numbering months starting from 1 for January. However, list items in
Python are numbered starting from 0. You need to take that into account.
Example
Note: Use this example to check your program. This is the output your program should produce.
The program displays the names of the These are the summer months:
summer months. June
July
August
14
Task 2 Name for a number
Step 1
15
Task 2 Name for a number
Step 2
Complete line 10 with an expression, so that the program displays the name of the current
month.
Tip: You are used to numbering months starting from 1 for January. However, list items in
Python are numbered starting from 0. You need to take that into account.
Example
Note: Use this example to check your program. Given the input you see in this sample interaction, this is the
output your program should produce.
The program displays a prompt and waits for What month is it? (1-12)
keyboard input.
Example
Note: Use this example to check your program. Given the input you see in this sample interaction, this is
the output your program should produce.
The program displays a prompt and waits What month is it? (1-12)
for keyboard input.
17
Task 3 Seasons
Step 1
18
13 print("It is", seasons[season])
Task 3 Seasons
Step 2
Complete lines 5, 7, and 9 with a Boolean expression (a condition) that checks the value of the
month variable and assigns an appropriate value to season.
Tip: The numbering of seasons is arbitrary. Looking at the seasons list, numbering ranges from
0 for winter to 3 for autumn.
Tip: The condition required in line 5 should check the month variable, to determine if it
corresponds to a winter month (season 0). The numbers for winter months are not consecutive
(1, 2, and 12), so you will need to use or in the condition.
19
Explorer Task (optional)
Instead of asking the user to type the current month, the program can retrieve the actual
month, using the datetime module.
Replace the lines that receive user input (marked with -) with the lines that retrieve the current
month (marked with +).
20