Repeating With a for Loop
A loop lets you repeat a block of code without copying it.
tools = ["rope", "map", "torch"]
for tool in tools:
print(tool)Here is what the example does:
toolscreates a list and stores it intools.- The
forloop takes each item fromtoolsone at a time and puts it intotool. print(tool)displays the value stored intool.
The assignment uses different values, but you will use the same loop pattern.
Assignment
Complete the starter code so the program does the following:
- Use a
forloop to go through eachnumberin[1, 2, 3]. - Inside the loop, print
number.
Your finished program should print exactly this output:
1
2
3Be very careful with capitalization, spaces, and line breaks. The output must match exactly.