2024-01-31
Max. 100 points
Name:
Task | Max. | Achieved |
---|---|---|
1 | 20 | |
2 | 40 | |
3 | 40 | |
Sum | 100 |
reverse(s: str) -> str
that reverses a
given string. To receive full points, make sure that the function has a
proper docstring and a doctest.
For example:
reverse("stressed") -> "desserts"
reverse("strops") -> "sports"
reverse("racecar") -> "racecar"
def reverse(text: str) -> str:
"""
Return a reversed version of the given string.
>>> reverse("stressed")
"desserts"
"""
return text[::-1]
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)
sumproduct(first iterable, second iterable)
in Python that takes two sequences of numbers with equal length and returns
the sum of the product of the numbers.sumproduct((1, 3, 4), (9, 2, 3)) ⇒ 1*9 + 3*2 + 4*3 = 27
;
sumproduct([3, 5], [2, 4]) ⇒ 26]
.
Add a proper docstring and a doctest to receive full points.def sumproduct(first, second):
"""
Return the sum of the products of `zip(first, second)`.
>>> sumproduct((1, 3, 4), (9, 2, 3))
27
"""
sum = 0
for i, j in zip(first, second):
sum += i * j
return sum