Uploaded by jochemvd12

Analysis (Math) - Python Exam with answers

advertisement
Analysis 2-1920
Foundations of modeling 2
This mock exam consists of 20 multiple-choice questions. For each question, only
one answer is correct. Each question is worth one point.
The regular exam consists of 40 multiple-choice questions. The cesuur is 26.5,
which means that you need 27 points to pass.
Write your answers on the answer sheet provided!
1
X
2
X
3
X
What is a list comprehension?
A
A list comprehension is a special Python operation that concatenates two or more lists into one.
B
A list comprehension is a Python function that “flattens” nested lists, returning a list of all the leaf
elements in one. Example: [[a, b, c], [d, e, f], [g, h i]] into: [a, b, c, d, e, f, g, h, i].
C
A list comprehension is a syntactic construct in Python that allows to create a list in a single line of
code.
D
A list comprehension is the way Python caches lists in memory to allow fast access when working
with large lists.
If a = [1,2,3], what is printed out with:
print(a + [1])
A
[2, 3, 4]
B
[1, 2, 3, 1]
C
[ [1,2,3], [1] ]
D
error
What is the printout of the following code:
a = [1, 5, 17, 42, 100]
b = a[::-2]
print(b)
A
[-1, 3, 15, 40, 98]
B
[42]
C
[1, 17, 100]
D
[100, 17, 1]
2
4
Which of the following relations is a function?
X
A
Only number 1 defines a function.
B
Only number 2 defines a function.
C
Only number 3 defines a function.
D
None of the above.
5
If y = 2x + 3, what is x in terms of y?
A
x = 2y - 3
B
x = 2y - 6
C
x = 0.5y - 3
X
D
x = 0.5y - 1.5
6
A scientist observed that the specimen F grows 18 cm per year. If specimen F was measured to be 90 cm
tall at the beginning of the experiment, how many years will it take for specimen F to double in height?
X
A
3
B
5
C
10
D
18
3
7
Which of the following is NOT the correct import syntax in Python?
A
import module_name
B
import module_name as object_name
C
from module_name import func_name
X
D
from module_name load func_name
8
The following code crashes due to an error in one of the lines. Which line is causing an error?
import matplotlib.pyplot as plt
N = 20
X = range(N)
F1 = [i**2 for i in range(N)]
F2 = [2 * i**2 for i in range(N)]
plt.plot(F1)
plt.plot(X, F1)
plt.bar(F2)
plt.bar(X, F2)
plt.show()
X
A
plt.plot(F1)
B
plt.plot(X, F1)
C
plt.bar(F2)
D
plt.bar(X, F2)
4
9
X
10
What are the values of the two following expressions?
(lambda x: x*x)(6)
(lambda x, y: x+x*y)(2, 3)
A
12
12
B
12
8
C
36
8
D
36
12
How can we rewrite the following code using a map and a filter?
[n**2 for n in range(100) if n%3 == 1]
A
list(filter(n%3 == 1, map(n**2, range(100))))
B
list(map(n**2, filter(n%3 == 1, range(100))))
C
list(filter(lambda n: n%3 == 1, map(lambda n: n**2, range(100))))
X
D
list(map(lambda n: n**2, filter(lambda n: n%3 == 1, range(100))))
11
What is dir() function used for?
X
A
Python dir() function is used to list all files in the current directory. E.g. ['documents',
'pictures', '..']
B
Python dir() function is used to list the directory path where Python libraries are stored. E.g.
“C:\Python\Lib”
C
Python dir() function without arguments returns the list of names in the current local scope. E.g.
['__annotations__', '__builtins__', '__doc__', '__loader__',
'__name__', '__package__', '__spec__', 'a', 'f']
D
Python doesn’t have dir() function by default. It can be anything and it’s behavior depends on the
implementation.
5
12
The decorator double is used to double the return of a lambda function. What is the proper syntax so that
for given x=10 the program outputs 200 to the console?
def double(f):
def f_(x):
return 2*f(x)
return f_
g=lambda x:x*x
x=10
X
13
X
A
print(double(g(x)))
B
print(double(g)(x))
C
print(double(g,x))
D
print(double(x,g))
What is wrong in the following code, meant to define a recursive function?
def sumlist(L):
if L == []: return 0
return sumlist([ L[0] ]+L[1:])
A
There is no stop criterion.
B
The function is not recursive.
C
The argument to the sumlist call in the body doesn’t get smaller.
D
The argument to the sumlist call in the body gets smaller at each call.
6
14
What does the following code do?
def fib(n):
if n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
fib(50)
X
15
X
16
A
It efficiently computes the 50th Fibonacci number.
B
It correctly computes the 50th Fibonacci number, but the computation takes ages to finish.
C
It will give a RecursionError.
D
The code will hang: it does not give an error but it will keep running forever.
Which of the following is true?
A
Permutations and combinations are ordered arrangements.
B
Permutations are ordered arrangements, while the order doesn’t matter in combinations.
C
Combinations are ordered arrangements, while the order doesn’t matter in permutations.
D
The order doesn’t matter in both permutations and combinations.
In how many different ways can a student answer Analysis 2 exam, which consists of 40 multiple-choice
questions, each with 4 options (A, B, C and D) to choose from.
A
!"#
$
"
B
"#!
"!
X
C
40"
D
4"#
7
17
5 prizes are awarded and 8 people in total have signed in. In how many different ways can the winners be
selected?
X
A
!()$
B
(!
)!
C
(!
*!
D
18
(8-5)!
A box contains 10 marbles, 6 white and 4 red. A person picks 3 marbles at once. What is the probability
that the person picks at least one white marble?
A
4 / 10
B
6 / 10
C
1 / 30
X
D
29 / 30
19
Requirements, principles or guidelines used to make a decision are:
X
A
Decision objectives.
B
Decision criteria.
C
Decision alternatives.
D
Decision support system.
8
20
In the model
p1
*
Y1t
X1t
the following is given:
X10 = 100 and p1 = 0,1 .
What is the value of X1 for t = 2?
X
A
1
B
100
C
120
D
121
9
Download