Exercises

This document contains hints for working on our exercise tasks.

Solution Script

The first line of solution must be a shebang line: #!/usr/bin/env python3

The solution script must be named solution.
It must not be named solution.sh or solution.py or… anything else, really.

The solution script must be executable. You can make it executable by executing chmod +x solution. You can check if your script is executable by running ls -l:

Good:

1
2
3
4
$ ls -l solution 
-rwxrwxr-x 1 user group 0 Aug  4 15:28 solution
   ↑  ↑  ↑
This script is executable for owner, group, and anybody else

Not good:

1
2
3
4
$ ls -l solution 
-rw-rw-r-- 1 user group 0 Aug  4 15:28 solution
   ↑  ↑  ↑
This script is not executable for owner, group, or anybody else

Dependencies

Your script solution must be executable on a fresh machine. Install all additional packages that are not available in the container we provide!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3

import sys
import subprocess
import importlib

def install(package, version):
    subprocess.check_call([sys.executable, "-m", "pip", "install", f"{package}=={version}"], stdout=subprocess.DEVNULL)
    globals()[package] = importlib.import_module(package)


def do_the_work():
    response = requests.get('https://shrug.fyi')
    print(response.text)


def main():
    install("requests", "2.25.1")
    do_the_work()


if __name__ == "__main__":
    main()

In order to avoid losing points, always check if your script executes properly in the provided container!

Files

If you need to patch a binary, push the binary to the repository as well!

1
2
    with open('fixme', 'rb') as f:
IOError: [Errno 2] No such file or directory: 'fixme'

Python Version

On our VMs and in the provided container:

1
2
$ python3 --version
Python 3.9.2

You cannot use language features from newer Python versions or from Python 2!