In [1]:
#Please execute this cell
import sys;
sys.path.append('../../'); 
import jupman;
jupman.init('../../')

#NOTE: init() injects js and css stuff, which might not be necessary for exercises 
#      and sometimes even undesirable
#      Please read https://jupman.readthedocs.io/en/latest/usage.html#Running-Jupyter
Out[1]:

Jupman - Exam Sunday 31, December 2000

TODO CHANGE COURSE - TODO CHANGE DEGREE

Download exercises

Introduction

  • Taking part to this exam erases any vote you had before, both lab and theory
  • If you don't ship or don't pass this lab part, you also lose the theory part.

Allowed material

There won't be any internet access. You will only be able to access:

  • Jupman worksheets
  • Alberto Montresor slides
  • Python 3 documentation (in particular, see unittest)
  • The course book "Problem Solving with Algorithms and Data Structures using Python"

Grading

  • Lab grade: The grade of this lab part will range from 0 to 30. Total grade for the module will be given by the average with the theory part of Alberto Montresor.
  • Correct implementations: Correct implementations with the required complexity grant you full grade.
  • Partial implementations: Partial implementations might still give you a few points. If you just can't solve an exercise, try to solve it at least for some subcase (i.e. array of fixed size 2) commenting why you did so.
  • Bonus point: One bonus point can be earned by writing stylish code. You got style if you:

    • do not infringe the Commandments
    • write pythonic code
    • avoid convoluted code like i.e.

        if x > 5:
            return True
        else:
            return False

      when you could write just

        return x > 5

Valid code

**WARNING**: MAKE SURE ALL EXERCISE FILES AT LEAST COMPILE !!! 10 MINS BEFORE THE END OF THE EXAM I WILL ASK YOU TO DO A FINAL CLEAN UP OF THE CODE
**WARNING**: _ONLY_ IMPLEMENTATIONS OF THE PROVIDED FUNCTION SIGNATURES WILL BE EVALUATED !!!!!!!!!

For example, if you are given to implement:

def f(x):
        raise Exception("TODO implement me")

and you ship this code:

def my_f(x):
    # a super fast, correct and stylish implementation

def f(x):
    raise Exception("TODO implement me")

We will assess only the latter one f(x), and conclude it doesn't work at all :P !!!!!!!

Helper functions

Still, you are allowed to define any extra helper function you might need. If your f(x) implementation calls some other function you defined like my_f here, it is ok:

# Not called by f, will get ignored:
def my_g(x):
    # bla

# Called by f, will be graded:
def my_f(y,z):
    # bla

def f(x):
    my_f(x,5)

How to edit and run

To edit the files, you can use any editor of your choice:

  • Editra editor is easy to use, you can find it under Applications->Programming->Editra.
  • Others could be GEdit (simpler), or PyCharm (more complex).

To run the tests, use the Terminal which can be found in Accessories -> Terminal

**IMPORTANT**: Pay close attention to the comments of the functions.
**WARNING**: _DON'T_ modify function signatures! Just provide the implementation.
**WARNING**: DON'T change the existing test methods, just add new ones !!! You can add as many as you want.
**WARNING**: _DON'T_ create other files. If you still do it, they won't be evaluated.

Debugging

If you need to print some debugging information, you are allowed to put extra print statements in the function bodies.

**WARNING:** even if print statements are allowed, be careful with prints that might break your function!

For example, avoid stuff like this:

x = 0
print(1/x)

What to do

1) Download jupman-2000-12-31-exam.zip and extract it on your desktop. Folder content should be like this:

jupman-2000-12-31-FIRSTNAME-LASTNAME-ID
    |-jupman.py
    |-other stuff ...
    |-exams
        |-2000-12-31
            |- examA_exercise.py
            |- examA_test.py
            |- examB_exercise.py
            |- examB_test.py

2) Rename jupman-2000-12-31-FIRSTNAME-LASTNAME-ID folder: put your name, lastname an id number, like jupman-2000-12-31-john-doe-432432

From now on, you will be editing the files in that folder. At the end of the exam, that is what will be evaluated.

3) Edit the files following the instructions in this worksheet for each exercise. Every exercise should take max 25 mins. If it takes longer, leave it and try another exercise.

1) MyClass

You are going to do.... something

In [5]:
from exercise1_solution import *
from exercise1_test import *

1.0) run EnvWorkingTest

Now open the file exercise1.py and check your environment is working fine, by trying to run the test EnvWorkingTest: it should always pass, if it doesn't, tell your instructor.

Notice that exercise1 is followed by a dot and test class name: .EnvWorkingTest

python -m unittest exercise1.EnvWorkingTest
In [6]:
jupman_run(EnvWorkingTest)
.
----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

1.1) do_something

Implement the method do_something:

def do_something(self):
        """ Does something """
        raise Exception("TODO IMPLEMENT ME !!!")

Testing

Once done, running this will run only the tests in DoSomethingTest class and hopefully they will pass.

Notice that exercise1 is followed by a dot and test class name .DoSomethingTest :

python -m unittest exercise1.DoSomething
In [7]:
jupman_run(DoSomethingTest)
.
Doing something
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

1.2) do_something_else

Implement the method do_something_else:

def do_something_else(self):
        """ Does something """
        raise Exception("TODO IMPLEMENT ME !!!")

Testing: python -m unittest exercise1.DoSomethingElse