Appendix B — Assignments

Published

October 9, 2026

B.1 Version control—assignment 1

—Goal

Create a pull request on the repository for these lecture notes that is worth merging.

(Please refrain from rewriting the thing from scratch. It is ok to use an LLM, if you really insist.)

—Specifications

  • Create an account on Codeberg, if you don’t have one, already.
  • Fork the repository for these lecture notes.
  • Find a weakness in the notes—I know, this one is hard. Anything will do: a typo in the text, a bug in one of the code snippets, a conceptual error, a link to an resource that you deem useful, a small additional piece of text that you think would be beneficial.
  • Create a new branch in your working copy. (Use a meaningful name for the branch.)
  • Edit your working copy as you see fit, and commit and push your changes.
  • Create a pull request against the original repository.
  • Wait for the pull request to be reviewed and merged. (There might be discussion on the pull request—please pay attention.)

B.2 Basic Python—assignment 1

Download a book (not covered by copyright) in plain-text format, e.g., from gutenberg.

(If you have a hard time picking one, we suggest the English translation of “The Republic” by Plato.)

—Goal

Write a Python program that prints the relative frequence of each letter of the alphabet (without distinguishing between lower and upper case) in the book.

—Specifications

  • The program should have a --help option summarizing the usage.
  • The program should accept the path to the input file from the command line.
  • The program should print out the total elapsed time.
  • The program should have an option to display a histogram of the frequencies.
  • [Optional] The program should have an option to skip the parts of the text that do not pertain to the book (e.g., preamble and license).
  • [Optional] The program should have an option to print out the basic book stats (e.g., number of characters, number of words, number of lines).

B.3 Basic Python—assignment 2

—Goal

Write a program to explore the properties of a few elementary particles. The program must contain a base class Particle and two child classes, Proton and Alpha, that inherit from it.

—Specifications

  • Instances of the class Particle must be initialized with their mass, charge, and name (all members should be read-only).
  • The class constructor must also accept (optionally) and store one and only one of the following quantities: energy, momentum, beta or gamma.
  • Whatever the choice, the user should be able to read and set any of these quantities using just the . (dot) operator, e.g., print(my_particle.energy), my_particle.beta = 0.5.
  • Attempts to set non physical values should be rejected.
  • The Particle class must have a method to print the particle information in a nicely formatted fashion.
  • The child classes Alpha and Protons must use class attributes to store their mass, charge and name.

B.4 Basic Python—assignment 3

—Goal

Create a ProbabilityDensityFunction class that is capable of throwing pseudo-random numbers with an arbitrary distribution.

(In practice, start with something easy, like a triangular distribution—the initial debug will be easier if you know exactly what to expect.)

—Specifications

  • The signature of the constructor should be __init__(self, x, y), where x and y are two numpy arrays sampling the pdf on a grid of values, that you will use to build a spline.
  • [Optional] Add more arguments to the constructor to control the creation of the spline (e.g., the order of the latter).
  • The class should be able to evaluate itself on a generic point or array of points.
  • The class should be able to calculate the probability for the random variable to be included in a generic interval.
  • The class should be able to throw random numbers according to the distribution that it represents.
  • [Optional] How many random numbers do you have to throw to hit the numerical inaccuracy of your generator?

B.5 Packaging—assignment 1

—Goal

Clean up your ProbabilityDensityFunction class and create a fully-fledged Python package.

(The layout of the package might draw inspiration from metarep.)

—Specifications

  • The package should have adequate unit tests.
  • The package should have continuous integration.
  • The package should have adequate documentation, and publicly accessible from the web.
  • [Optional] Add a rudimentary release manager to automate the tagging process.

B.6 Advanced Python—assignment 1

—Goal

Write a class to handle a sequence of voltage measurements at different times.

—Specifications

  • The class name must be VoltageData.
  • The class must be initialized with two generic iterables of the same length holding the numerical values of times and voltages.
  • Alternatively the class can be initialized from a text file.
  • The class must expose two attributes: timestamps and voltages, each returning a numpy array (of type numpy.float64) with the corresponding quantity.
  • The values should be accessible with the familiar square parenthesis syntax: the first index must refer to the entry, the second selects time (0) or voltage (1). Slicing must also work.
  • Calling the len() function on a class instance must return the number of entries.
  • The class must be iterable: at each iteration, a numpy array of two values (time and voltage) corresponding to an entry in the file must be returned.
  • The print() function must work on class instances. The output must show one entry (time and voltage), as well as the entry index, per line.
  • The class must also have a debug representation, printing just the values row by row.
  • The class must be callable, returning an interpolated value of the tension at a given time.
  • The class must have a plot() method that plots data using matplotlib. The plot function must accept an ax argument, so that the user can select the axes where the plot is added (with a new figure as default). The user must also be able to pass other plot options as usual.
  • [Optional] Support a third optional column for the voltage errors.
  • [Optional] Add unit tests.