2021-02-03
Max. 32 points
Name:
| Task | Max. | Achieved |
|---|---|---|
| 1 | 6 | |
| 2 | 10 | |
| 3 | 8 | |
| 4 | 8 | |
| Sum | 32 |
| Statement | True | False |
|---|---|---|
| In Python, any block of code creates scope. | ||
| Python has different versions. Old code may not work with newer versions, new code may not work with older versions. | ||
Execution of all Python programs starts in
main(). | ||
| pip allows installing and updating third party libraries. | ||
| Python code written with VSCodium cannot be edited with another editor afterwards. | ||
| A Python sequence type can be indexed, sliced and iterated. | ||
| Strings in Python are immutable. | ||
| Python lists are immutable. |
| Statement | True | False |
|---|---|---|
| In C, any block of code creates scope. | ||
The entry point of any C program is
main(). | ||
| Clang and gcc are aliases for the same C compiler. | ||
| C has different versions and different compilers. A program working with one compiler may not work with another compiler. |
def average(a, b, c):
return (a + b + c) / 3.0
average(4, 2, 3)
def square(length):
return length * length
print(square(5))
s = 'Good luck!'
s.upper()
print(s)
sum = lambda x, y: x + y
print (sum (3, 4))
from collections import namedtuple
Point = namedtuple ('Point', ('x', 'y'))
A = Point(x=2, y=3)
rot13(text) assuming that text only contains
upper case characters. Use the ord(char)->int and
chr(i:int)->str functions in your implementation.
Add a proper docstring in order to receive full points.
def rot13(text):
"""Return the input string after returning the characters by 13 places."""
result = []
for char in text:
if 'A' <= char <= 'M':
num = ord(char) + 13
elif 'N' <= char <= 'Z':
num = ord(char) - 13
else:
num = ord(char)
result.append(chr(num))
return "".join(result)
2022-02-02T19:49,1175 2022-02-02T19:59,1235 2022-02-02T20:09,1481 ... 2022-02-02T22:09,753 2022-02-02T22:19,819Implement a function
average_co2(filename: str) -> float that returns
the average CO2 in the given file.
Add a proper docstring to receive full points.def average_co2(filename: str) -> float:
"""
Return average CO2 from the given file.
"""
count = 0
total = 0
with open(filename) as f:
for line in f:
total += int(line.split(',')[-1])
count += 1
return total / count