# Hands On¶

## Questions¶

- What uses do the different brackets have: `[]`, `()`, `{}`
- Give a possible use for each of the following container: Dictionary, Set, Tuple
- What is a keyword-argument? Where in the list of arguments do keyword-arguments belong?
- You can type `my_func?` to geht help on `my_func`. If you wrote `my_func`, what do you need to do to get a useful help-text?
- When do you use `for`-loops, when `while`? Give an example of both loops.
- What is the difference between `break`, `continue` and `return`?
- After reading the content of a file, how do you restart reading from the first line?
- Why is it a good idea to use a contect-manager when reading files?
- What is the difference between a string defined with `"String"` and `r"String"`
- What does `sys.argv[0]` return?

## Tasks¶

- Improve your refugee code
  - store the three data variables (`years`, `countries`, `refugees`) into a sensible data structure.
  - adapt the plot function such that it accepts arbitrary keyword-arguemnts and passes unknown arguments on to the plot function.
  - add a command-line interface using `argparse`

- In the data directory you find `gdp-europe.csv`. This file contains the GDP per capita for the same countries as refugees.
  - Add the data to your script.
  - Calculate and plot the refugee number relative to the GDP.
  - Create a scatter plot with all countries.

- Implement a library, that provides basic formulas from Macro- or Microeconomics. (You probably know better what you could implement then me.) Each formula should be implemented as a separat function taking the relevant parameters as arguments.

- Write a simple command-line interface that provides access to the functions in your library from above. (You can either expect the relevant input on the command line or ask for it interactively.

- Have a look at https://docs.python.org/3.6/library/turtle.html. Implement something nice with it :-)

### Brute Force¶

Assume you find the following password comparison in the source code.
`from hashlib import md5 ... if md5(pin.encode()).digest() == hash: ...`

In addition you know that the pin is 1 to 4 digits long.

md5 is a bad hashing algorithm for passwords. So it should be straight forward to brute-force the password. (try all possible combinations)

In [1]:

    hash = b'P\xc1\xf4NBe`\xf3\xf2\xcd\xcb>\x19\xe3\x99\x03'

Once this works adapt the code to use `argon2` instead of `md5`. You will still be able to brute-force such a short pin. It should however take significantly longer.

## Small Problems¶

Download the file `exercises.zip` and look at the `.py` files. Choose one ore more of the problems and solve them.