Iteration – While Loops Python Iteration – While Loops
biscuits = 3 Iteration What does iteration mean? Answer: Computing term for repeatedly doing a set of actions biscuits = 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
While biscuits > 0 eat_biscuit biscuits = biscuits -1 Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1
While biscuits > 0 eat_biscuit biscuits = biscuits -1 Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1
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
Activity 2 Guess My Number Download the starter code: http://bit.ly/2JPZ7qA Or https://www.ict4u.net//Python/includes/CodeTxt/Guess%20My%20Number.txt to your Python Coding folder. Save as Guess My Number The code contains two syntax errors. Fix the code to make it work
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