Search Header Logo
Python - Introduction to While Loops

Python - Introduction to While Loops

Assessment

Presentation

Computers

8th - 11th Grade

Medium

Created by

Martin Dunn

Used 118+ times

FREE Resource

10 Slides • 9 Questions

1

Python - While Loops


Slide image

2

While Loops

A while loop is a block of code that will keep repeating until a condition has been met.



Slide image

3

Looping (Iteration)

  • Looping code in programming is called "Iteration"

  • You can re-use the same code over and over again.

  • This saves on the amount of code you have to write.

4

Example

  • This example asks you what the capital city of France is.

  • It keeps asking the same question if your answer is not Paris.

Slide image

5

Multiple Choice

In programming, what is iteration?
1
The repetition of steps within a program
2
The order in which instructions are carried out
3
A decision point in a program
4
Testing a program to make sure it works

6

Multiple Choice

Why is iteration (looping) important?

1

It determines the order in which instructions are carried out

2

It allows code to be simplified by removing duplicated steps

3

It allows multiple paths through a program

4

It ensures the code works correctly

7

Conditions that cause and stop a loop.

Loops can sometime be stuck in an infinite loop

Slide image

8

Slide image

This can be fixed by asking for a user input for the variable "play" during each loop.

The loop will carry on if you type "yes" (meeting the condition)

Typing anything else will stop the loop.

9

Using a Counter

This loop will print out "Let's play" each time is runs.

After every loop, the counter increases by one.

It continue to loop while the counter is less than 5

What happens when the counter reaches 5?

Slide image

10

Multiple Choice

Question image

How many times will this program print out "Let's play before the loop stops?"

1

4

2

5

3

0

4

9

11

Whay was the answer 5 times?

  • The counter for the loop begins at 0.

  • the looping happened when the counter was 0,1,2,3 and 4

12

Multiple Choice

Question image

How many times will this loop run before it exits?

1

3

2

5

3

4

4

10

13

Conditions

  • Equal to ==

  • Less than <

  • Greater Than >

  • Less than or equal to <=

  • Greater than or equal to >=

  • Not equal to !=

14

Multiple Choice

The condition for a while loop to continue could include which of the following?
1
While something equals something
2
While something is greater than something
3
While something is True
4
All of these

15

Multiple Choice

Which of the following symbols is used in Python to mean "Greater than or equal to"?
1
<=
2
>>
3
>=
4
=>

16

Multiple Choice

Which of the following symbols is used in Python to mean "Not equal to"?
1
==
2
!=
3
<>
4
><

17

Multiple Choice

Which of the following symbols is used in Python to mean "Equal to"?
1
=
2
!=
3
==
4
>=

18

Multiple Choice

Which type of loop iterates (loops) until instructed otherwise?

1

FOR loop

2

A count-controlled loop

3

Repeat-once loop

4

WHILE loop

19

Using "break" to end a loop

In this example, the loop is still set to run 5 times.

On each loop you are asked the question "what is 2+2".

If you answer correctly, you are told "correct" and the loop breaks.

Slide image

Python - While Loops


Slide image

Show answer

Auto Play

Slide 1 / 19

SLIDE