Python - Lesson 2

Python - Lesson 2
1 / 21
next
Slide 1: Slide
ComputingLower Secondary (Key Stage 3)

This lesson contains 21 slides, with interactive quizzes, text slides and 2 videos.

time-iconLesson duration is: 50 min

Items in this lesson

Python - Lesson 2

Slide 1 - Slide

The alien is back! They have heard about this amazing thing called Python programming. They want to take this back to their planet! Explain what is Python and why is it cool?

Slide 2 - Open question

KO: To be-able to use selection statements with variables.
All
  • To be able to identify variables in coding and be able to know what they do.

Most 
  • To be able to create algorithms in Python that contain variables and selection (If Statements).

Some
  • Are able to explain how IF statements work and how they validate a users input.
  • Are able to explain how variables work and how they store data and are subject to change.

Slide 3 - Slide

What is the correct version of code?
A
print("Hello World")
B
print"(Hello World")
C
print((Hello World))
D
print(Hello World")

Slide 4 - Quiz

Slide 5 - Video

What is a variable?

Slide 6 - Open question

What is a Variable?
In programming, a variable is a named storage location in a computer's memory that can hold a value. The value stored in a variable can be changed throughout the program's execution, hence the term "Variable".

Slide 7 - Slide

Recap - Variables
Using this example, I want you to go and create your own sentence, using 'Variable'.

Example

name = "bob" 
print("Hello my name is", name)

Slide 8 - Slide

Recap - Variables
Storing an 'Input' inside a 'Variable'.
Example 
name = input("Please can you enter your name?")
school = input("Please can you enter your school?")
print("Hello, your name is", name, "and you go to", school)


Slide 9 - Slide

Debugging Task
Can you find out what is wrong with the code?

First person to correct all mistakes, wins
A GOLDEN TICKET!

Click here

Slide 10 - Slide

Slide 11 - Video

What is selection (If Statements)?

Slide 12 - Open question

Selection (If Statements)
Selection allows us to make decisions in our programs.
The code we use, are IF statements.

Below is an example

IF I want to play on my PS5 THEN
I need to switch the PS5 on

Else
I leave the PS5 switched off.


Slide 13 - Slide

Example

Slide 14 - Slide

IF Statements
Let's take a look at how it works.

Click here

Slide 15 - Slide

Indentation
  • You may notice in my code, that some of the lines have been indented.
  • There is a reason for this.
  • Python requires indentation for the syntax.
  • Indentation signifies the start and end of a block of code.
  • Programs will not run.

Slide 16 - Slide

Comparison Operators

Slide 17 - Slide

Challenge Time!
Golden Ticket is up for grabs...
Scenario
Age must be 18 to go into a club.
I want to go to a club, but I want to check whether I am old enough. If I am old enough, the program must say "You can go to the party" and if I am not old enough, the program must say, "You can't go to the party".

Comparison Operator you must use is -  >=

Slide 18 - Slide

Answer

Slide 19 - Slide

What is the comparison operator for not equal to?
A
!=
B
<=
C
>=
D
==

Slide 20 - Quiz

Can you provide an example of an "if statement" in Python and explain how it works?

Slide 21 - Open question