AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Python loops

Week 6 · 1.4 Loops in text-based programming · 3 lessons
Answers are for parents and teachers.
1
Write two Python programs. One prints Hello 6 times. The other prints the numbers 1 to 6.
2
Write this pseudocode as a Python for loop. Then say what is printed.
Pseudocode
1FOR m ← 3 TO 7
2    OUTPUT m * 10
3NEXT m
3
What does this program print at the end?
Python
1total = 0
2for n in range(1, 5):
3    total = total + n * n
4print(total)
4
This program should print 1 to 5, but it has three mistakes. Find all three and write the correct program.
Python
1For c in range(1, 5)
2    print(c)
5
Explain in your own words why for k in range(2, 6) runs 4 times and not 5 times. How can you work out the number of runs without listing the values?