Presentation is loading. Please wait.

Presentation is loading. Please wait.

Iteration – While Loops

Similar presentations


Presentation on theme: "Iteration – While Loops"— Presentation transcript:

1 Iteration – While Loops
Python Iteration – While Loops

2 biscuits = 3 Iteration What does iteration mean? Answer:
Computing term for repeatedly doing a set of actions biscuits = 3

3 biscuits = 3 Iteration There are two types of iteration:
Definite - Counter Controlled Indefinite – Condition Controlled In this presentation we will be considering indefinite This means the loop will continue until the condition is met. It could be the condition is never met which means it is infinite biscuits = 3

4 While biscuits > 0 eat_biscuit biscuits = biscuits -1
Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1

5 While biscuits > 0 eat_biscuit biscuits = biscuits -1
Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1

6 Activity 1 Open a new Python code window and enter the following code:
Save it as While Loop Modify your code to: Ask the user how many times to loop. Replace the constant 5 with the variable you have created Only print the value of count when it is equal to 3 Print the value of count when the loop has finished

7 Activity 2 Guess My Number
Download the starter code: Or to your Python Coding folder. Save as Guess My Number The code contains two syntax errors. Fix the code to make it work

8 Activity 2 Guess My Number
Extending the code Give clues to the player prompting them if their guess was too high or too low Count the number of times the player guesses and report this number at the end of the game Limit the number of guesses a player can attempt an a game to a number you choose Stop the game when the limit has been reached


Download ppt "Iteration – While Loops"

Similar presentations


Ads by Google