Coderbyte
Coderbyte
You can share this report with people via the URL above Save PDF
Code quality & documentation Private notes to share with your team...
Python3 skills
Recommendation
Video recordings
Python Age Counting Video 1
3. We need to Execute a function wrapped with a logger that prints ‘hi’ before the execution
You and ‘bye’ after
can share it. Thewith
this report execution prints
people via something
the URL above on Save
its runtime
PDF
too.
The expected result is:
Hi!
Here is your coffee.
Bye!
// Option A
def logger():
def inner(*args,**kwargs):
print('Hi!')
f(*args, **kwargs)
print('Bye!')
return inner
@logger
def f1():
f1()
// Option B
def logger(f):
def inner():
print('Hi!')
f(*args,**kwargs)
print('Bye!')
return inner
@logger
def f1():
f1()
// Option C
def logger(f):
def inner(*args,**kwargs):
print('Hi!')
f(*args, **kwargs)
print('Bye!')
return inner
@logger
def f1():
f1()
// Option D
def logger(f):
def inner(*args,**kwargs):
print('Hi!')
f(*args,**kwargs)
print('Bye!')
return inner
@logger
def f1():
f1()
X Option B
4. We have the following function. We expect to retrieve only comma-separated values, the first being a string, containing the name of the user, the second,
being the highest number of session actions per user.
m = {}
// CODE TO FILL
return m
Which code should replace “//CODE TO FILL” line in order to achieve this?
// Option A
Try:
s, f = line.split(“,”)
Except:
Continue
If s not in m:
m[s]= 0
https://coderbyte.com/report/userxdwmukfmv:python-assessment-k05k07jde2 2/4
12/28/21, 3:39 PM Coderbyte
m[s] = max( int(f), m[s])
You can share this report with people via the URL above Save PDF
// Option B
Try:
s,f = line.split()
Except:
Break
// Option C
Try:
s,f = line.split(“,”)
Except:
If s not in m:
M[s] = 0
// Option D
Try:
s,f = line.split(“,”)
Except:
Return m
✔ Option A
✔ List
x = 1
class B(A):
pass
class C(A):
pass
We do 3 executions as follows:
// First exec
// Second exec
>>> B.x = 2
// Third Exec
>>> A.x = 3
X funct_1(3,3,3,k=3, b=3)
a.append(5)
return a
X [5]
10. Given this class A that you import from an external library:
https://coderbyte.com/report/userxdwmukfmv:python-assessment-k05k07jde2 3/4
12/28/21, 3:39 PM Coderbyte
self.x = 1
self._y = y + 10
You can share this report with people via the URL above Save PDF
def my_other_method(self):
self.x * 2
11. Which one of these is not a possible use of single underscore in Python (“_”):
✔ Create dataclasses
12. Given snippets A and B, if someone asks you which is better, what do you say?
# Snippet A:
def f(x):
return 2*x
# Snippet B:
f = lambda x: 2*x
13. This is my code and I need to open the file and append to the end the content of my_row.
Which should the value of OPENING_MODE be?
import csv
my_row = [1, 2, 3]
OPENING_MODE = ??
f.write(my_row)
✔ 'a'
https://coderbyte.com/report/userxdwmukfmv:python-assessment-k05k07jde2 4/4