2024-01-22
Max. 100 points
Name:
Task | Max. | Achieved |
---|---|---|
1 | 12 | |
2 | 24 | |
3 | 36 | |
4 | 28 | |
Sum | 100 |
Statement | True | False |
---|---|---|
Python is so successful because of its fast execution performance. | ||
Inheritance and polymorphism are concepts of functional programming | ||
Composition and aggregation are concepts of object oriented programming | ||
Finding an element in a sequence is computationally more complex than sorting the sequence. | ||
Python packages can be downloaded and installed using
pip . | ||
Pandas is a library that focuses on data analysis. |
def sum(a, b):
return b + c
print(sum(4, 2))
def area(length):
return length ** 2
print(area(5))
s = 'Hello World!'
s.lower()
print(s)
class S:
def __init__(self):
self.__i = 0
s = S()
print(s.i)
def fun(a):
if a == 1:
return 1
return a + fun(a - 1)
print(fun(3))
def print_together(a, b):
print(a, b)
print_together(b='XMAS!', a='Merry')
cumsum(l: List[int]) -> List[int]
in Python that takes a list of integers and returns
a list containing the cumulative sum of the numbers. For examplecumsum([9, 2, 3]) -> [9, 9+2, 9+2+3] -> [9, 11, 14]
cumsum([3, 5, -4, 2]) -> [3, 8, 4, 6]]
def cumsum(l: List[int]) -> List[int]:
"""Return the cumulative sum of the given list."""
if not l: return []
r = l[:1]
for e in l[1:]:
r.append(r[-1] + e)
return r
to_rna(dna_strand: str) -> str
that determines the RNA complement
of a given DNA sequence.
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (A), cytosine (C),
guanine (G) and thymine (T). The four nucleotides found in RNA are
adenine (A), cytosine (C), guanine (G) and uracil (U).
Given a DNA strand as a string (only consisting of upper case
characters 'G', 'C', 'T' and 'A'), return its transcribed RNA strand as
string. This is done by replacing each nucleotide with its complement:
G -> C C -> G T -> A A -> UFor example,
to_rna('GCGGATA') -> 'CGCCUAU'
.
Add a proper docstring to receive full points.
def to_rna(dna_strand: str) -> str:
"""Return RNA strand for given DNA strand."""
l = []
for c in dna_strand:
if c == 'G':
l.append('C')
elif c == 'C':
l.append('G')
elif c == 'T':
l.append('A')
elif c == 'A':
l.append('U')
return ''.join(l)
# one of many alternatives that are more elegant:
def to_rna(dna: str) -> str:
"""Return RNA strand for given DNA strand."""
translations = {'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U'}
return ''.join([translations[n] for n in dna])