Yguoo

In: English and Literature

Submitted By uigiug
Words 264
Pages 2
Worksheet 4: Loops 1. Put a tick next to each print statement if you think the while() loop will run.
Put a cross next to each program if you think it won’t. Program | Will the loop run? | A | score = 200 while score < 150: print("... | No | B | score = 200 while score > 150: print("... | Yes | C | name = "Fred" while name != "Fred": print("... | Yes | D | answer = 42 while answer == 42: print("... | Yes | 2. How many times will each of these for() loops run? Program | How many times will the loop run? | A | for counter in range(10): | 10 | B | for counter in range(20): | 20 | C | for counter in range(1,20): | None | D | for counter in range(3,23): | None |

3. For each situation, say whether it would be best to use a while() loop or a for() loop. Program | Which kind of loop? | A | I need a program that will keep letting me add money to a piggy bank until I get to £100. | For | B | I need a program that will keep letting me add a monthly payment for 12 months. | While | C | I need a guessing game program that will let me keep guessing until I get the right answer. | While | D | I need a revision program that will run through revision questions 4 times. | For |

4. Try writing the code to create these loop statements: a. A program that will keep letting me add money to a piggy bank untIl I get to £100.

b. A program that will let me keep adding a monthly payment for 12…...

Similar Documents