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

Repeat and reuse

Week 5 · 1.3 Creating algorithms · 3 lessons
Answers are for parents and teachers.
1
Write three loops. (a) Output Hello 8 times with the counter starting at 1. (b) Do the same with the counter starting at 0. (c) Output the numbers 10 to 15.
2
Trace the algorithm for n = 5, and then for n = 0. Give the output each time.
Pseudocode
1INPUT n
2total ← 0
3FOR i ← 1 TO n
4    total ← total + i
5NEXT i
6OUTPUT total
3
Write pseudocode. The user types how many pets they have, then the weight of each pet in kg. Output the total weight and the average weight. Make it safe if the user has no pets.
4
Give two reasons why a programmer writes a sub-routine instead of copying the same lines again and again.
5
Write a sub-routine greet() that outputs Good morning. In the main part, call it three times with a loop, and then once more only if the user types yes. How many lines are output when the user types no?