Year 9 Python recap

Year 9 Python Recap
Go to Lessonup.com.

Enter the on-screen code.
1 / 21
volgende
Slide 1: Tekstslide
ComputingLower Secondary (Key Stage 3)

In deze les zitten 21 slides, met interactieve quizzen en tekstslides.

Onderdelen in deze les

Year 9 Python Recap
Go to Lessonup.com.

Enter the on-screen code.

Slide 1 - Tekstslide

Constructs of Programming
x = 10
if x > 5:
    print("x is greater than 5")
else:
    print("x is not greater than 5")

for i in range(5):
    print(i)
Repetition of a process until something specific happens.
Run in a specified order.
Run in an order based on decisions or questions.
name = "Alice"
age = 30
print("Name:", name)
print("Age:", age)
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)
x = 10
if x > 5:
    print("x is greater than 5")
elif x == 5:
    print("x is equal to 5")
else:
    print("x is less than 5")

Slide 2 - Sleepvraag

Constructs of Programming 2
Selection
Iteration
Repetition of a process until something specific happens.
Run in a specified order.
Run in an order based on decisions or questions.
Sequencing

Slide 3 - Sleepvraag

Key Objectives

All: Identify the three key programming constructs and loops.
 Most: Code the three key constructs and loops.
Some: Understand the purpose of the three key constructs and loops.


Slide 4 - Tekstslide

What are these an example of?
a = 0
name = "Mr. Motley"
A
Selection
B
User input
C
Declaring variables
D
Iteration

Slide 5 - Quizvraag

num1 = 10
num2 = 5
result = num1 - num2 * 2
What is the value of result?
A
0
B
5
C
-5
D
20

Slide 6 - Quizvraag

Code task
Carlie's Carpets has hired you to develop a simple app to calculate how much carpet each customer needs.
Write a Python program that calculates the area of a rectangle given its length and width. 
Prompt the user to enter the length and width as inputs.
Calculate and display the area of the required carpet.
Open a new trinket here.  Comment breakdown here.

Slide 7 - Tekstslide

Compare with your trinket.

Did you use a float?
Why wouldn't you use an integer?

Slide 8 - Tekstslide

Think: Three loops?
Silent and solo: 
What are the three kinds of loop?
What is each one for?

Slide 9 - Tekstslide

Pair: Three loops?
In pairs:
Discuss what the three loops are.
Discuss what they're for.

Slide 10 - Tekstslide

One member of each pair:
Share the purpose of a "for loop".

Slide 11 - Open vraag

For loops
A "for" loop is used to execute a block of code repeatedly until a specified condition is met. 
It's particularly useful when you know in advance how many times you want to execute a block of code.

# Iterate over elements in a list
numbers = [1, 2, 3, 4, 5]
for number in numbers:
    print(number)



Slide 12 - Tekstslide

One member of each pair:
Share the purpose of a "while loop".

Slide 13 - Open vraag

While loops
A "while" loop is used in programming to execute a block of code repeatedly as long as a specified condition is true. 
The purpose of a while loop is to automate repetitive tasks and to iterate over a sequence of instructions until a certain condition is no longer met.

# Print numbers from 1 to 5 using a while loop
count = 1
while count <= 5:
    print(count)
    count += 1


Slide 14 - Tekstslide

Explain the purpose of a "do-while" loop.

Slide 15 - Open vraag

Do-while loops
A "do-while" loop executes a block of code at least once and then repeats the execution based on a specified condition. 
The purpose of a do-while loop is to ensure that the block of code is executed at least once, regardless of whether the condition is initially true or false.
count = 0
while True:
    print(count)
    count += 1
    if count >= 5:
        break

Slide 16 - Tekstslide

Code task: Times Tables
Times Table Generator:
Task: 
Write a program that generates the times table for a number entered by the user three times. 
1. Use a for loop to iterate through the numbers from 1 to 10 and print the multiplication result for each.
2: Repeat this using a while loop.
3: Repeat this using a do-while loop.
Open a new trinket here.

Slide 17 - Tekstslide

Code task: Times Tables
Times Table Generator:
Task: 
Write a program that generates the times table for a number entered by the user three times. 
1. Use a for loop to iterate through the numbers from 1 to 10 and print the multiplication result for each.
2: Repeat this using a while loop.
3: Repeat this using a do-while loop.
Open a new trinket here.

Slide 18 - Tekstslide

Why would we use loops (iteration)?

Slide 19 - Open vraag

Why loops?
Automation: Loops help automate repetitive tasks by executing the same code multiple times without manual work. 

Iterating over Data: Loops allow programmers to iterate over data such as lists, arrays, or dictionaries. 
Reducing Code Redundancy: Instead of writing the same code multiple times for each iteration, loops enable writing concise and efficient code by encapsulating the repetitive logic within a loop structure.
Scalability: Loops make programs scalable by allowing them to handle varying amounts of data or perform tasks a specific number of times.



Slide 20 - Tekstslide

Rate the Lesson
😒🙁😐🙂😃

Slide 21 - Poll