Python - Lesson 2

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

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

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

Éléments de cette leçon

Python - Lesson 2

Slide 1 - Diapositive

KO: To be-able to use selection statements with variables.
All
  • To be-able to use variables in programming.
  • To be-able to use print statements in programming.

Most 
  • To be-able to explain why selection statements are used to validate a users input.

Some
  • To be-able to create code, using variables and selection statements to validate an input.

Slide 2 - Diapositive

Thinking back to last weeks lesson.

What is the purpose of programming?

Slide 3 - Question ouverte

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

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 5 - Diapositive

Slide 6 - Vidéo

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 7 - Diapositive

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 8 - Diapositive

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 9 - Diapositive

What would the output be for this code?

food = "pizza"
print("orange")
A
print pizza
B
food
C
orange
D
pizza

Slide 10 - Quiz

What would the output be for this code?

myname = bob
name = input("please enter your name")
print(name)
A
bob
B
name
C
john
D
myname

Slide 11 - Quiz

Slide 12 - Vidéo

Selection 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 - Diapositive

Example

Slide 14 - Diapositive

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

Click here

Slide 15 - Diapositive

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 - Diapositive

Comparison Operators

Slide 17 - Diapositive

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 - Diapositive

Answer

Slide 19 - Diapositive

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

Slide 20 - Quiz

What does a selection statement do?

Slide 21 - Question ouverte