Python - Updated

Python 
Year 7 - Lesson 1 
1 / 45
suivant
Slide 1: Diapositive
ComputingLower Secondary (Key Stage 3)

Cette leçon contient 45 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 7 - Lesson 1 

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
Run
Investigate
Modify
Make

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

MAKE
Create your own program that will:

Slide 9 - Diapositive

Slide 10 - Vidéo

What is Syntax?
  • The way we write a line of code is important, as the computer needs to recognise it.
  • Think about our 'English'. It is important that we use correct punctuation, such as Commas and Full Stops. If we didn't, it would make our writing difficult to read.
  • If we do not use the correct symbols and spellings in our Python coding, then the computer will not be-able to run our programs.


Slide 11 - Diapositive

What is debugging?
  • Debugging code refers to the process of identifying and fixing errors, bugs, or defects in a computer program that we have created.

  • An error occurs, when you have done something wrong in your program. You could have spelt something wrong or even missed out a symbol...

Slide 12 - Diapositive

Debugging Continued...
Create with code, shows you where your error is. Below is a screenshot that shows this.

Slide 13 - 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 14 - Diapositive

Slide 15 - Vidéo

Variables 
  • In programming, a variable is like a container that holds a piece of information. This information can be anything, like a number, a word, or even a whole sentence!


  • For example, imagine you have a box that can hold a piece of fruit. You can put an apple in the box, and then later on, you can take the apple out and look at it or even swap it for a banana. In programming, a variable is like that box. You can put information into the variable, and then you can use that information later on in your program and change it as you please.



  • To use a variable, you first need to give it a name. This is like labelling the box with the word "fruitbox" so you know what's inside. In programming, you can choose any name you want for your variable, as long as it follows certain rules. For example, the name can't have spaces in it, and it can't start with a number.



Slide 16 - Diapositive

Task 3 - Variables - Predict
PREDICT




Slide 17 - Diapositive

What do you think the code will do?

Slide 18 - Question ouverte

Slide 19 - Diapositive

INVESTIGATE and MODIFY
Using the code try the following:
  • make the program call the other two procedures
  • 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 20 - Diapositive

Taking input
We can ask the user for inputs into our programs.
So lets get the computer to do this

Slide 21 - Diapositive

PREDICT

Slide 22 - Diapositive

What do you think this code will do when run?

Slide 23 - Question ouverte

Slide 24 - 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 25 - 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 26 - 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 27 - 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 28 - Question de remorquage

Commenting our code. What is the importance?
  • By commenting our code,  it tells you (the programmer) and anyone else who looks at the code what it does.

  • By using the '#' symbol, it will not display when your code has been run.

  • You have been seeing them since we started but you have to start using them to help you explain what you are doing


Slide 29 - Diapositive

What symbol do I use to comment code?

Slide 30 - Question ouverte

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 31 - 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 32 - Quiz

Adding conditions
We have been taking inputs, storing variables and outputting results to the screen
Now we need to add some conditions.

Slide 33 - Diapositive

PREDICT

Slide 34 - Diapositive

What do you think this code would do?

Slide 35 - Question ouverte

Slide 36 - Diapositive

Slide 37 - 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 38 - 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 39 - 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

Slide 40 - Diapositive

PREDICT

Slide 41 - Diapositive

Slide 42 - 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

Slide 43 - 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 44 - Diapositive

Slide 45 - Diapositive