-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise7.py
More file actions
62 lines (44 loc) · 1.64 KB
/
exercise7.py
File metadata and controls
62 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from collections.abc import Callable
from typing import Any, Generic, TypeVar
class Car:
def __init__(self, kleur):
self.colour = kleur
class Exercise7():
"""
Exercise 7: Functions.
Internal note:
An exercise class must be the same name as the file but with a capital first letter and must always contain a tests, runExercise and checkResults.
The array output of tests should always be able to be used as input for checkResults
"""
def runExercise(self) -> list[bool]:
# So efficient! Are you enjoying this?
#
# In this task we will make use of the function functionality.
#
# Task:
# - Shorten this code by making a function without breaking the program.
resultList: list[bool] = []
# ALTER CODE BELOW
myCar = Car('rood')
if (myCar.colour == 'geel'):
resultList.append(True)
else:
resultList.append(False)
myCar.colour = 'blauw'
if (myCar.colour == 'geel'):
resultList.append(True)
else:
resultList.append(False)
myCar.colour = 'geel'
if (myCar.colour == 'geel'):
resultList.append(True)
else:
resultList.append(False)
# ALTER CODE ABOVE
return resultList
def tests(self) -> list[list[bool]]:
return [self.runExercise()]
def checkResults(self, exerciseResults: list[list[bool]]):
print('with the colours changing to rood, blauw, geel:')
print('expected outcome: [False, False, True]')
print(f'your result: {exerciseResults[0]}\n')