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

Which is better?

Week 9 · 1.6 Comparing algorithms · 3 lessons
Answers are for parents and teachers.
1
The requirements are: ask for a distance in kilometres and output it in miles (1 kilometre is about 0.6 miles). Write a plain version in Python. Then write a more robust version that rejects a distance below 0. What do they print for 10 and for −4?
2
This program asks for a word and prints twice its length. The user types tree. How many variables does it use? Rewrite it with fewer variables.
Python
1word = input("Word? ")
2length = len(word)
3doubled = length * 2
4print(doubled)
3
A program uses one variable but gives wrong answers. Another program uses three variables and works. A friend says the first is more efficient. Do you agree? Explain.
4
Two ways to collect homework from 20 pupils. Method A: the teacher walks to every desk. Method B: each row passes its books along to the front. Both collect all the books. Which uses fewer steps for the teacher? Write a verdict with one reason.
5
Rank the three programs from best to worst, with a reason for each place.
ProgramRequirements metRobust?Variables
X3 of 3no6
Y3 of 3yes4
Z3 of 3no4