Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

for() loops

For loops are used when we DO know how many times we want the block of code to repeat

If we wanted to print out the numbers 1-10 we could do the following:

print ("1")

print ("2")

.....

for() loops

You can add a second 'argument' by separating the values with a comma.

What do you think this will do?

A much easier and efficient way would be to use a for loop

  • counter is the name of the loop.
  • the number in brackets is the 'argument'

for() loops

When you played the guessing game, did you know how many guesses your partner would take to get the right answer?

Lesson Objectives:

Starter

1. What will happen the first time this loop runs?

2. How many times will the loop run in total?

  • Use a while loop to repeat a section of code
  • Use a for loop to repeat a section of code
  • To identify the most appropriate loop for a task and give reasons as to why you selected it.

Loops

"A sequence of instructions that is continually repeated until a certain condition is reached."

In other words, do something over and over until we tell you to stop

Python - Lesson 3

60 second task

While() Loops

In pairs I want you to play the number guessing game.

Loops

A while() loop works like an if() statement that repeats. Like an if() statement, you need a rule.

I need a volunteer...

Task

Tell me...

Admin time

I want to print the numbers up to 10. Will the following code work?

Imagine asking for 1p per week pocket money. The deal is that it will double each week so in week 2 you get 2p, in week 3 you get 4p etc.

  • Print screen the code you have created today.

  • Print screen the program running in the shell

  • Put your name on the word document before printing and tagging.

If I want to print the numbers 10 - 37, what arguments should I set the for loop to?

This might sound a bit rubbish, but complete worksheet 3 and you may be better off than you think

Plenary

Complete the plenary activity.

Worksheet 4 - loops

Learn more about creating dynamic, engaging presentations with Prezi