-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise3.py
More file actions
56 lines (39 loc) · 1.86 KB
/
exercise3.py
File metadata and controls
56 lines (39 loc) · 1.86 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
from collections.abc import Callable
from typing import Any, Generic, TypeVar
class Exercise3():
"""
Exercise 3: Scope.
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, a: int) -> int:
# Like 2 colleagues but on a different floor?
#
# In this task we will see how scope can effect our program. This is not really an excersice but more of a show and tell.
#
# Task:
# - Run the program and view how the a gets set multiple times
# - Create a variable inside the if named 'a' with number 8 as value
# - See how your variable a will be the result everytime instead of the a defined earlier
a = a # the program will run multiple times and fill this a with many numbers
if(True):
# ALTER CODE BELOW
# ALTER CODE ABOVE
# return a
return a
def tests(self) -> list[int]:
return [self.runExercise(11), self.runExercise(-62), self.runExercise(73), self.runExercise(2000)]
def checkResults(self, exerciseResults: list[int]):
print('with a being 11:')
print('expected outcome: \'8\'')
print(f'your result: {exerciseResults[0]}\n')
print('with a being -62:')
print('expected outcome: \'8\'')
print(f'your result: {exerciseResults[1]}\n')
print('with a being 73:')
print('expected outcome: \'8\'')
print(f'your result: {exerciseResults[2]}\n')
print('with a being 2000:')
print('expected outcome: \'8\'')
print(f'your result: {exerciseResults[3]}\n')