Multiple Choice Questions (15 Questions, 1 point each)
For these MCQs, you have to put your answers in the BUBBLESHEET to receive your marks.
Circling options on this exam paper will NOT be accepted as answers.
In all these questions, the first option corresponds to A, the second to B, the third to C, the
fourth to D, and the fifth to E on the bubble sheet.
If the choices have ⃝ then select exactly one option.
If the choices have □, correct options may be more than one and you should select all correct
options.
Now, get your BUBBLESHEET ready and start to complete this section of MCQs.
1. (1 mark) Read the Python code snippet above. When running this code, what will be the
output printed to the screen?
1 speed =25.1
2 if speed < 20.0:
3 print('low')
4 elif speed < 40.0:
5 print('medium')
6 elif speed < 60.0:
7 print('high')
8 else:
9 print('dangerous')
⃝ medium
⃝ low
⃝ high
⃝ dangerous
2. (1 mark) Consider the list comprehension shown in the Python code below:
1 data=[2, -1, 3,-1, 4]
2 data_out=[i for i in data if i>0]
What will the contents of the list ”data out” be after these lines of code?
⃝ data_out = [2,-1,3,-1,4]
⃝ data_out = [2,3,4]
⃝ data_out = [-1,3,-1,4]
⃝ data_out = [-1,-1]
3. (1 mark) Consider the Python dictionary shown below:
1 phone_nums = {'Debby': 999, 'Abe': 555, 'John': 101, 'Wei':
222, 'Steph': 767}
What python code would be used to access the value associated to the key ’Abe’ in the
dictionary shown above?
⃝ phone_nums[555]
⃝ phone_nums.Abe
⃝ phone_nums['Abe']
⃝ phone_nums['Wei']
4. (1 mark) Consider the python code shown in the code below:
1 A = {1, 2, 3, 4}
2 B = {3, 4, 5, 6}
3 new_set = A.intersection(B)
After running this code, what are the contents of the Python set ”new set”?
⃝ {1,2,3,4}
⃝ {1,2,3,4,5,6}
⃝ {3,4,5,6}
ENGG1810/9810 Practice Exam Page 2 of 9
⃝ {3,4}
5. (1 mark) Consider the Python code shown below:
1 def my_function(a):
2 x = 10
3 return a + x
4 b = my_function(2)
5 print(x)
Why does this code produce an error when trying to print the variable x?
⃝ Because the variable x has global scope and should be accessible from outside the
function.
⃝ Because the variable x defined inside the function has local scope, and cannot be
accessed outside of the function.
⃝ This code does not produce any errors in Python: there are not problems with
this.
⃝ Because code inside the function is trying to access variables that have not been
defined.
6. (1 mark) Consider the Python code shown below:
1 def my_sum(a, b=10, c=20):
2 return a + b + c
3 value = my_sum(1,c=25)
4 print(value)
What is the output produced by this code?
⃝ 36
⃝ 26
⃝ 31
⃝ 46
7. (1 mark) Consider the Python code shown below:
1 hot = False
2 raining = True
3 windy = False
4
5 if hot:
6 if raining:
7 print('visit_friends')
8 else:
9 print('beach')
10 else:
11 if windy:
12 print('stay_home')
13 elif raining:
14 print('stay_home')
15 else:
16 print('walk_in_the_park')
ENGG1810/9810 Practice Exam Page 3 of 9
What is the output of this code?
⃝ visit friends
⃝ stay home
⃝ walk in the park
⃝ beach
8. (1 mark) Consider the Python code shown below:
1 for i in range(2,10):
will go through the following values of i:
⃝ 2, 3, 4, 5, 6, 7, 8, 9
⃝ 2, 3, 4, 5, 6, 7, 8, 9, 10
⃝ 3, 4, 5, 6, 7, 8, 9
⃝ 3, 4, 5, 6, 7, 8, 9, 10
9. (1 mark) How would you index and print out the name ’Missie’ ?
1 dogs = pd.Series(['Freddie', 'Archie', 'Pepper', 'Missie', '
Arthur', 'Skylar', 'Harry'])
⃝ print(dogs['Missie'])
⃝ print(dogs['3'])
⃝ print(dogs[3])
⃝ print(dogs(3))
10. (1 mark) You are given a dataset containing the test scores of 500 students on a single
exam. Your goal is to understand the distribution of scores. Which function will you use
to do this?
⃝ plt.scatter()
⃝ plt.pie()
⃝ plt.plot()
⃝ plt.hist()
11. (1 mark) Consider a free-dropping ball and we aim to write a dynamics simulator for it. In
the part of the code shown below, what does x represent?
1 for k in range(n_steps-1):
2 x[k+1] = dynamics_function(x[k])
□ The position of the ball.
□ The velocity of the ball.
□ The position and velocity of the ball.
□ The state of the ball.
12. (1 mark) Consider the system:
x(k + 1) = −x2 (k) + 2
Select all correct statement.
ENGG1810/9810 Practice Exam Page 4 of 9
⃝ There are two equilibria: -1 and 2.
⃝ There are two equilibria: 1 and -2.
⃝ There is no equilibrium.
√ √
⃝ There are two equilibria: 2 and − 2.
13. (1 mark) Select the correct objective function for a least squares fit:
PT ′ 2
⃝ k=1 |yk − yk |
PT ′
⃝ k=1 |yk − yk |
PT ′2 2
⃝ k=1 yk − yk
′ 2
PT 2
⃝ k=1 |yk | − |yk |
14. (1 mark) Which of the following best describes an equilibrium of a discrete dynamical
system
x[k + 1] = f (x[k])
⃝ A value of x[k] where the system diverges.
⃝ A value where f(x[k])=0.
⃝ A point where the system exhibits chaotic behavior.
⃝ A point where x[k+1]=x[k].
15. (1 mark) What components do you need to build a constrained optimization script?
□ Objective Function
□ Decision Variables
□ Constraints
□ Optimiser
ENGG1810/9810 Practice Exam Page 5 of 9
Short Answer Questions (2 questions, 2 Marks each)
For these Short Answer Questions, write brief answers within the provided boxes
below. Your answer does not need to fill the whole box.
16. (2 marks) Write one line of Python code to create a new list called ”data lengths” that
contains the length of each string in ”data”, sorted in descending order.
1 data = ["apple", "banana", "cherry", "watermelon"]
17. (2 marks) You are preparing to plot the curves of two different functions, each displayed in
its own subplot (arranged vertically). Complete the code in line 6 and line 9:
• In the first subplot, plot the curve of log(x + 1) using diamond markers (’D’),
marker size 6, a green solid line (’-’), and add a legend label ‘Log Curve”.
• In the second subplot, plot the curve of x3 − 2x2 + x using cross markers (’x’),
marker size 7, a blue dotted line (’:’), and add a legend label “Cubic Curve”.
1 import numpy as np
2 import matplotlib.pyplot as plt
3 x = np.linspace(0, 3, 100)
4 fig, ax = plt.subplots(2, 1)
5 y1 = np.log(x + 1)
6 # Complete the code to plot log(x + 1) on ax[0]
7 ax[0].legend()
8 y2 = x**3 - 2*x**2 + x
9 # Complete the code to plot the cubic on ax[1]
10 ax[1].legend()
11 plt.show()
ENGG1810/9810 Practice Exam Page 6 of 9
Programming Questions: (1 Questions, 6 Marks each)
In the next few questions, you will be given a task and a set of lines of code to do the task.
Decide which lines to use and what order to place them in. Write the line numbers in order
in the grids provided (one number in each box, in order from top to bottom). Note:
• If multiple orders are correct, we will accept all correct answers.
• You do not need to indicate indentation.
• Not all lines need to be used, and some lines may be used more than once.
• We provide more boxes than are needed.
• If you make a mistake, clearly put a line through the numbers and write a new response
in the boxes.
ENGG1810/9810 Practice Exam Page 7 of 9
18. (6 marks) the motion of a ball falling through the air could be described by the equations:
v[k + 1] = v[k] + g × dt
y[k + 1] = y[k] + v[k] × dt
where g = −9.81 m/s2 is the acceleration due to gravity, v is the velocity of the ball, y is
the position of the ball, and dt is the simulation time step.
Assume velocity, height , total number of simulation steps and time steps are initialized as
v0, y0, n steps and dt.
Use the code lines below to create a program with dynamics f unction that simulates the
ball dropping from a height.
1 x[k+1] = dynamics_function(x[k])
2 y_new = 0
3 y = x[:,0]
4 for k in range(n_steps-1):
5 v_new = v_k + g * dt
6 x = np.zeros((n_steps, 2))
7 v_k = x_k[1]
8 if y_new <= 0:
9 v = x[:,1]
10 y_k = x_k[0]
11 y_new = y_k + v_k * dt
12 x[0] = np.array([y0, v0])
13 def dynamics_function(x_k):
14 v_new = 0
15 return np.array([y_new, v_new])
ENGG1810/9810 Practice Exam Page 8 of 9
END OF EXAMINATION
ENGG1810/9810 Practice Exam Page 9 of 9