-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise2.py
More file actions
48 lines (33 loc) · 1.67 KB
/
exercise2.py
File metadata and controls
48 lines (33 loc) · 1.67 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
from collections.abc import Callable
from typing import Any, Generic, TypeVar
class Exercise2():
"""
Exercise 2: Data types.
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: str) -> int:
# But when I'm writing on paper they ARE the same!
#
# In this task we will encounter that theres more to a variable then just the value its holding.
# You can already use variable a. No need to create.
#
# Task:
# - Create a variable which holds a number/int, this number should be a number-ified version of the string in variable a
# - Return this variable by typing: `return {variable}` (lets run the program to see if all went fine, one test didnt :O)
# - If the type-changing wasnt possible, return -5
# CREATE CODE BELOW
# CREATE CODE ABOVE
def tests(self) -> list[int]:
return [self.runExercise('1'), self.runExercise('46'), self.runExercise('hello there')]
def checkResults(self, exerciseResults: list[int]):
print('with a being \'1\':')
print('expected outcome: 1')
print(f'your result: {exerciseResults[0]}\n')
print('with a being \'46\':')
print('expected outcome: 46')
print(f'your result: {exerciseResults[1]}\n')
print('with a being \'hello there\':')
print('expected outcome: -5')
print(f'your result: {exerciseResults[2]}\n')