Below is some code that has been deliberately broken so that you can fix it.
It’s supposed to give the following program output for the Old McDonald Had a Farm nursery rhyme:
- Change the mouse noise so that it eeks rather than moos
Hint: The order of the values in the lists on lines 2 and 3 is important
- Add an empty line between each verse
Hint: Indentation controls which lines are repeated.
- Change it so that it says the correct verse number rather than verse 1 each time
Line 5 creates a variable called
iwhich is used in the
forloop to count from 0 to the length of
animals(0, 1 and 2). You can use this variable to display the verse numbers you want (1, 2 and 3)
Hint: remember to convert your integer to a string with
On the next page you’ll get some ideas for projects where you can use iteration to create your own projects