Commit 49e43ba2 authored by Gökçe Aydos's avatar Gökçe Aydos
Browse files


parent 7e876112
Pipeline #17324 passed with stage
in 8 minutes and 6 seconds
%% Cell type:code id:bd8c5cb6-ddf0-479c-a862-880138235531 tags:
``` python
# ✏️
# example: 12345678 or "12345678"
SEAT_ID = None
# example "Deggs 1.04-7510" or 7510
%% Cell type:code id:a7e1d513-5a90-474e-95c1-4d941a7bbddb tags:
``` python
isinstance(eval(n), int) or
isinstance(eval(n), str)
), f"You forgot to enter your {n}"
%% Output
AssertionError Traceback (most recent call last)
Input In [9], in <cell line: 1>()
----> 2 assert(
3 isinstance(eval(n), int) or
4 isinstance(eval(n), str)
5 ), f"You forgot to enter your {n}"
AssertionError: You forgot to enter your MATRICULATION_NUMBER
%% Cell type:markdown id:72874a72-4fd8-47f9-bda2-544c569b1cc5 tags:
# LSI-M Informatics 2 exam 22SS (2022-06-26)
Examiner: Gökçe Aydos
- Browse the problems before you start solving.
- Some cells may create files which are part of the question. Run all the cells from the beginning if you begin a new notebook.
- Write your answers only on the exam notebooks and not on extra files.
- The exam contains many practical problems which may take vast amount of time if you do not know the time-efficient approach. Additionally the interactive nature of the notebooks may motivate you to try again and again. Postpone the question if you have spent much time.
- In coding problems, you may also explain your approach in sentences or pseudocode if your code does not work straightaway.
- Remove the placeholders like `# YOUR CODE HERE`, `raise NotImplementedError` if you answer a problem
- In some problems, partial answers are already provided. It should be sufficient to replace the `# YOUR CODE HERE; raise NotImplementedError` lines in these.
- Some cells may be completely empty, ignore them.
- In multiple-choice and `True`/`False` questions a wrong answer has penalty. The penalty equals to the half of the points of a correct answer.
- The examiner evaluates *your* understanding of the syllabus. Do not provide answers to the questions without understanding, e.g., by copying from other sources.
## Bash
The exam may contain Bash-related problems.
- If a cell starts with the line `%%bash`, then the whole cell is run in Bash. In answer cells, `%%bash` may already be provided.
- Some commands could show a lengthy error where most of the output is not related to the actual error, do not let it trip you up. The actual error in your Bash command will be right after the cell.
- If cell line starts with `!` then only this line is run in your shell, e.g., Bash, zsh, so make sure that your default shell is Bash if you want to execute Bash commands with `!`.
## Python
- Pay attention to the difference between *returning* and *printing* in functions
- Code style will also be graded (max 10% penalty in each question). You may use a code linter.
## Good luck! 🤞
# Questions
To display the notebooks, run the following cell.
%% Cell type:code id:ac9716f4 tags:
``` python
import _header; _header.display_html()
%% Output
<IPython.core.display.HTML object>
Calculates total points on every notebook and displays them on an HTML table
import glob
import json
def notebook_to_points_dict():
ipynbs = glob.glob('*.ipynb')
nb_pts = dict() # filename: points
for ipynb in ipynbs:
with open(ipynb) as f:
nbjson = json.load(f)
total_points = 0
for cell in nbjson['cells']:
# 'points' key exists in autograder cells only
points = cell['metadata']['nbgrader']['points']
except KeyError:
total_points += points
nb_pts[ipynb] = total_points
return nb_pts
def ipynb_points_html(notebook_to_points):
# remove '.ipynb' from filenames
notebook_to_points = {k[:-6]: v for k, v in notebook_to_points.items()}
# add sum
footer = dict()
footer['∑'] = sum(v for v in notebook_to_points.values())
from jinja2 import Template
template_content = """
<th> Notebook </th>
<th> Points </th>
{% for key, value in data.items() %}
<th> <a href="{{ key }}.ipynb" target="_blank"> {{ key }} </a> </th>
<td> {{ value }} </td>
{% endfor %}
{% for key, value in footer.items() %}
<th> {{ key }} </th>
<td> {{ value }} </td>
{% endfor %}
template = Template(template_content)
# template rendering embedded in the HTML representation
return template.render(data=notebook_to_points, footer=footer)
def display_html():
from IPython.display import HTML
return HTML(ipynb_points_html(notebook_to_points_dict()))