Exercises: Recognising “Plans”
Mar 192018Before attempting these exercises, you should read the posts on specifying problems, problem-solving and algorithmic “plans”.
Exercises
- Name the plans used in the following code, and specify the problem this function solves.
def exercise1(numbers): for i, value in enumerate(numbers): numbers[i] = 10 * value
- Name the plans used in the following code, and specify the problem this function solves.
def exercise2(numbers): total = 0 for value in numbers: cube = value ** 3 total += cube return total
- Name the plans used in the following code, and specify the problem this function solves.
def exercise3(numbers, cutoff): for i, value in enumerate(numbers): if value >= cutoff: return i return -1
- Name the plans used in the following code, and specify the problem this function solves.
def exercise4(strings, max_length): counter = 0 for value in strings: if len(value) > max_length: counter += 1 return counter
There are no published comments.