1 - Which of the following open modes allow you to perform read operations? (Select two answers)
a) r
b) a
c) r+
d) w
Solution: c
2 - What is the expected result of executing the code?
def I():
s = 'abcdef'
for c in s[::2]:
yield c
for x in I():
print(x, end=' ')
a) It will print abcdef
b) It will print an empty line
c) It will print bdf
d) It will print ace
Solution: d
3 - What keyword would you us to define an anonymous function?
a) afun
b) lambda
c) def
d) yield
Solution: b
4 - Select the true statements. (Select two answers)
a) The lambda function can accept a maximum of two arguments
b) The lambda function can evaluate multiple expressions
c) The lambda function can evaluate only one expressrion
d) 1The lambda function can accept any number of arguments
Solution: c, d
5 - Look at the code below:
my_list = [1, 2, 3]
# insert line of code here.
print(foo)
Which snippet would you insert in order for the program to output the following result (tuple):
1, 4, 27
a) foo = list(map(lambda x: x**x, my_list))
b) foo = tuple(map(lambda x: x*x, my_list))
c) foo = list(map(lambda x: x*x, my_list))
d) foo = tuple(map(lambda x: x**x, my_list))
Solution: d
6 - What is the expected output of the following code?
from datetime import date
date_1 = date(1992, 1, 16)
date_2 = date(1992, 2, 5)
print(date_1 - date_2)
a) 345
b) 345 days
c) 345, 0:00:00
d) 345 days, 0:00:00
Solution: d
7 - Which program will produce the following output:
Mo Tu We Th Fr Sa Su
a) import calendar
print(calendar.weekheader(3))
b) import calendar
print(calendar.weekheader(2))
c) import calendar
print(calendar.week)
d) import calendar
print(calendar.weekheader())
Solution: b
8 - What is the expected result of executed the following code?
def o(p):
def q():
return'*' *p
return q
r = o(1)
s = o(2)
print(r9) + s())
a) it will print ***
b) it will print ***
c) it will print **
d) it will print *
Solution: a
9 - Look at the code below:
my_tuple = (0, 1, 2. 3, 4, 5, 6)
# Insert line of code here.
print(foo)
Which snippet would you insert in order for he program to output the following result (list):
[2, 3, 4, 5, 6]
a) foo = list(filter(lambda x: x-0 and x-1, my_tuple))
b) foo - list(filter(lambda x: x==0 and x==1, my_tuple))
c) foo = tuple(filter(lambda x: x>1, my_tuple))
d) foo = tuple(filter(lambda x: x-0 and x-1, my_tuple))
Solution: a
10 - What is the expected result of executed the following code?
def fun(n):
s = '+'
for i in range(n):
s += s
yield s
for x in fun(2):
print(x, end='')
a) It will print+++
b) It will print ++
c) It will print ++++++
d) It will print +
Solution: b
11 - What is the meaning of the value represented by errno.EEXITS ?
a) File doesn’t exist
b) Bad file number
c) Permission denied
d) File exists
Solution: d
12 - What is the expected result of the following code?
b = bytearray(3)
print(b)
a) 3
b) bytearray(b'\x00\x00\x00')
c) bytearray(0, 0, 0)
d) bytearray(b'3')
Solution: b
13 - What is the expected output of the following code?
from datetime import datetime
datetime = datetime(2019, 11, 27, 11, 27, 22)
perint(datetime.strftime('%y/%B/%d %H:%M:%s'))
a) 19/November/27 11:27:22
b) 2019/Nov/27 11:27:22
c) 2019/11/27 11:27:22
d) 19/11/27 11:27:22
Solution: a
14 - What is the expected output of the following code?
import os
os.mkdir('pictures')
os.chdir('pictures')
os.mkdir('thumbnails')
os.chdir('thumbnails')
os.mkdir('tmp')
os.chdir('../')
print(os.getcwd())
a) The orint to the thumbnails directory
b) The path to the pitcures directory
c) The path to the tmp directory
d) The path to th root directory
Solution: b
15 - What is the expected output of the following code?
import os
os.mkdir('thumbnails')
os.chdir('thumbnails')
sizes = ['small', 'medium', 'large']
for size in sizes:
os.mkdir(size)
print(os.listdir())
a) ['.', '..', 'large', 'small', 'medium']
b) []
c) ['.', 'large', 'small', 'medium']
d) ['large', 'small', 'medium']
Solution: d
16 - What is the expected result of the following code?
import calendar
c = calendar.Calendar()
for weekday in c.iterweekdays():
print(weekday, end="")
a) 1 2 3 4 5 6 7
b) Su Mo Tu We Th Fr Sa
c) 0 1 2 3 4 5 6 7
d) Mo Tu We Th Fr Sa Su
Solution: c