import algolab
algolab.init()
Real exam will be in the lab with restricted internet access. You will only be able to access:
You won't be able to use anything else, in particular:
So if you need to look up some Python function, please start today learning how to search documentation using the search functionality on Python website.
One extra point can be earned by writing stylish code. You got style if you:
avoid convoluted code like i.e.
if x > 5:
return True
else:
return False
when you could write just
return x > 5
%%HTML
<p class="algolab-warn">
!!!!!!!!! WARNING !!!!!!!!!
<br/>
<br/>
!!!!!!!!! **ONLY** IMPLEMENTATIONS OF THE PROVIDED FUNCTION SIGNATURES WILL BE EVALUATED !!!!!!!!! <br/>
</p>
For example, if you are given to implement:
def cool_fun(x):
raise Exception("TODO implement me")
and you ship this code:
def cool_fun_non_working_trial(x):
# do some absurdity
def cool_fun_a_perfectly_working_trial(x):
# a super fast, correct and stylish implementation
def cool_fun(x):
raise Exception("TODO implement me")
We will assess only the latter one cool_fun(x)
, and conclude it doesn't work at all :P !!!!!!!
Still, you are allowed to define any extra helper function you might need. If your cool_fun(x)
implementation calls some other function you defined like my_helper
here, it is ok:
def my_helper(y,z):
# do something useful
def cool_fun(x):
my_helper(x,5)
# this will get ignored:
def some_trial(x):
# do some absurdity
%%HTML
<p class="algolab-warn">
WARNING: <i>DON'T</i> modify function signatures! Just provide the implementation.
</p>
<p class="algolab-warn">
WARNING: <i>DON'T</i> change the existing test methods, just add new ones !!! You can add as many as you want.
</p>
<p class="algolab-warn">
WARNING: <i>DON'T</i> create other files. If you still do it, they won't be evaluated.
</p>
<p class="algolab-important">
IMPORTANT: Pay close attention to the comments of the functions.
</p>
3) Every exercise should take max 25 mins. If it takes longer, leave it and try another exercise.
4) When you're done, proceed with the submission
1) Zip your files into a file named exam.zip
2) Upload the zip to file.io
2) After the upload you should see a download link (something like https://file.io/C40YFy
)
3) Copy paste the link into the common ethercalc here:
%%HTML
<p class="algolab-warn">
WARNING: REMEMBER TO WRITE SOMEWHERE (IN YOUR COMPUTER OR ON PAPER) YOUR DOWNLOAD LINK, OTHERWISE IT
WILL BE HARD FOR YOU TO UNDERSTAND WHICH ZIP WAS CORRECTED.
</p>
Insertion sort is a basic sorting algorithm. This animation gives you an idea of how it works:
Here is the pseudo code:
%%HTML
<p class="algolab-warn">
WARNING: The following pseudo code contains a bug (just one!).
</p>
<p class="algolab-important">
IMPORTANT: <br/>
Array <i>A</i> in the pseudo code has indexes starting from zero included. <br/>
<i>n</i> is the length of the input array.
</p>
Start editing the file exercise1.py
:
Implement in Python the pseudocode for insertion_sort
. Make sure at least the provided tests pass (they won't check for the bug).
We said the given pseudo code has a bug. Write additional test cases that show where the bug is, and then fix the code accordingly.
%%HTML
<p class="algolab-warn">
WARNING: <i>DON'T</i> modify function signatures! Just provide the implementation.
</p>
<p class="algolab-warn">
WARNING: <i>DON'T</i> change the existing test methods, just add new ones !!! You can add as many as you want.
</p>
<p class="algolab-important">
IMPORTANT: Pay close attention to the comments of the functions.
</p>
We are going to have some more fun with good old UnorderedList
, which is a monodirectional linked list.
Start editing the file exercise2.py
:
Implement the method rev(self)
that you find in the skeleton and check provided tests pass.
Implement the method copy(self)
that you find in the skeleton and check provided tests pass.