Python Stage 1 - Updated for Y9 2025

Python 
Year 9 
Self guided learning slides
1 / 50
suivant
Slide 1: Diapositive
ComputingLower Secondary (Key Stage 3)

Cette leçon contient 50 diapositives, avec quiz interactifs, diapositives de texte et 4 vidéos.

time-iconLa durée de la leçon est: 50 min

Éléments de cette leçon

Python 
Year 9 
Self guided learning slides

Slide 1 - Diapositive

KEY OBJECTIVE
To program a computer using the python programming language

Slide 2 - Diapositive

Slide 3 - Vidéo

PRIMM
We will be using the PRIMM approach when we learn to code

Predict - look at code and guess what it does
Run - run the code and see it work
Investigate - understand what the code is doing
Modify - make changes to existing code
Make - write a program based on what we have seen

Slide 4 - Diapositive

Task 1 - PREDICT
What do you think this code will do?

Slide 5 - Diapositive

What will the code do?

Slide 6 - Question ouverte

Slide 7 - Diapositive

INVESTIGATE and MODIFY
Using the code you have try and:
  • make it say a different message
  • Make the message print 3 times by calling the procedure multiple times

Slide 8 - Diapositive

Guidance on MAKE stage (RED pages)
  • These start with a blank template and you need to write the code from scratch.
  • You can use the previous code to reference and check code
  • DO NOT copy and paste code as this will not help you learn the syntax 
  • Look at existing code, switch to the blank and recall it by typing 
  • Remember you always have a similar version to look at from the initial RUN stage so you don't get lost

Slide 9 - Diapositive

MAKE
Create your own program that will:

Slide 10 - Diapositive

Slide 11 - Vidéo

What is Syntax?
  • Rules of writing the code
  • Breaking the rules means errors


So it is important!

  • where spaces are and aren't
  • where punctuation marks are like ""
  • using colons : correctly
  • using indentation


Slide 12 - Diapositive

What is debugging?
  • You will make mistakes....frequently
  • When this happens you will get error messages
  • You need to remove the bugs to make it work
  • So we call this debugging

Slide 13 - Diapositive

Debugging Continued...
Here is an error you might get.
Errors are either on the line it tells you or the one before the line
So if your error message says line 7 look carefully at lines 6 and 7 for the error.

Slide 14 - Diapositive

Common errors to look for
  • Missing "" or () or : where they are needed
  • wrong name for a variable
  • indent levels are wrong 

Slide 15 - Diapositive

Task 2 - Debugging
In this task, you will need to debug the code using the error messages that create with code provide.

Click here

Slide 16 - Diapositive

Slide 17 - Vidéo

Variables 
  • Computers need to store data for you that the program needs (like health, XP, points)
  • These are called VARIABLES
  • In python we declare these using a suitable name and then assign them values

LIKE
health = 100
xp = 0
points = 0

All Variables should:
  • Have a sensible name
  • be lower case
  • have no spaces (only one word long)



Slide 18 - Diapositive

Task 3 - Variables - Predict
PREDICT




Also - can you spot the variable in this code?

Slide 19 - Diapositive

What do you think the code will do?

Slide 20 - Question ouverte

RUN
run the code
The variable in this code is of course name
but something weird happens when you run it
How good was your prediction?

Slide 21 - Diapositive

Nothing happened?
Check over the code carefully
Sometimes you do not get errors as the computer thinks the code is fine
Look at the last line and how the procedure was called
Notice anything that's missing?

Slide 22 - Diapositive

INVESTIGATE and MODIFY
Using the code try the following:
  • Fix the call for procedure1 to include the ()
  • make the program call the other two procedures as well
  • Change the name in the printing2 procedure to your name
  • (Harder) Add more text after the greeting in printing3 so it will print the following --> "Hello Sally , nice to meet you"

Slide 23 - Diapositive

Taking input
We can ask the user for inputs into our programs.
So instead of setting a variable to store "bob" we can ask the user what their name is and store that instead. 

Slide 24 - Diapositive

PREDICT

Slide 25 - Diapositive

What do you think this code will do when run?

Slide 26 - Question ouverte

Slide 27 - Diapositive

INVESTIGATE AND MODIFY
Try and do the following:
  • change the procedure name for printmyname() to printname()
  • add two more input questions to the askmestuff() procedure about a favourite hobby and place in the world and store them in suitable variables
  • add another print statement to the same procedure to print suitable text using the new stored variables.

Slide 28 - Diapositive

MAKE
Create your own program that:
  • has a procedure that asks 2 questions and stores them as variables
  • calls this procedure from the main code
  • results in a sentence being printed, using the stored variables
  • Here is a blank coding window

Slide 29 - Diapositive

Syntax errors?
Let's test some of those error checking skills
On the next drag and drop which bits of code are correct and which would cause an error?

Slide 30 - Diapositive

CORRECT
CAUSE AN ERROR
print = ("Hello")
Print("Yes!")
print("this one)
name = imput("what is your name")
name = input("what is your name")
print("this text")
fav colour = "Green"
age = 10
print("Hello", name)
print("Bye",name")

Slide 31 - Question de remorquage

Commenting our code. What is the importance?
  • Comments are like post-it notes on your code
  • The computer will ignore them when you write them
  • The explain code and help you come back and edit it later 
  • Look at the first code you saw - where are the comments?

Slide 32 - Diapositive

What symbol is used to tell Python you are writing a comment?
A
:
B
""
C
()
D
#

Slide 33 - Quiz

What is the process of checking a program for errors by running it and fixing the issues?
A
Error checking
B
De-bugging
C
Error finding
D
Mistake finding

Slide 34 - Quiz

What type of information can be stored in a variable?
A
Only videos
B
Only sounds
C
Only pictures
D
Numbers, text, and other types of data

Slide 35 - Quiz

Adding conditions
We have been taking inputs, storing variables and outputting results to the screen
Now we need to add some conditions.
So we only do things when certain things happen and not all the time

Slide 36 - Diapositive

PREDICT

Slide 37 - Diapositive

What do you think this code would do?

Slide 38 - Question ouverte

Slide 39 - Diapositive

Comparisons in code
x==10
when x is equal to the value 10
x!=10
when x does not equal 10
x>10
when x is greater than 10
x<10
when x is less than 10
x>=10
when x is greater or equal to 10
x<=10
when x is greater or equal to 10

Slide 40 - Diapositive

Slide 41 - Vidéo

Investigate and Modify
Change the code here to do the following:
  • Change the condition to check if the name is equal to "Bob"
  • if it is "Bob" then say "Hey there Bob! I know you!"
  • else then print out "Have you seen Bob anywhere?"

Slide 42 - Diapositive

MAKE
Make a program that
  • Has a procedure called checkfood():
  • Ask the user to enter their favourite food and store it as a suitable variable
  • Check if their favourite food is "pizza" or not
  • If it is then print something positive about it
  • If it isn't then say something negative about it
  • Call the procedure you made in the main code routine
  • Here is a blank to code in

Slide 43 - Diapositive

If this, if that
  • Sometimes we need to check for more than one thing
  • And we need to check for certain things in a certain order
  • This is where "elif" comes in 
  • it stands for ELSE IF
  • you only check the elif when the first if has failed
  • you can then add as many of these as you like
  • and they get checked in order until one if met
  • if none are met then the code under the ELSE part will run
  • ELSE will only EVER RUN when the IF and ELIFs have all failed

Slide 44 - Diapositive

PREDICT

Slide 45 - Diapositive


Slide 46 - Question ouverte

Slide 47 - Diapositive

Investigate and Modify
With this code try and:
  • Edit the names and responses the code is looking for in the various statements
  • add an additional elif statement to look for an additional name (maybe yours)

Slide 48 - Diapositive

MAKE
Make your own version of an if/elif/else statement which:
  • Has a procedure defined appropriately
  • asks the user to enter a favourite animal
  • checks the animal against 4 different animals, each with a specific response if they are selected
  • prints that it doesn't like the animal if it is not one of these 4
  • calls the written procedure in the main code routine
  • You can use this blank

Slide 49 - Diapositive

Slide 50 - Diapositive