```
In [2]:
```import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'png'
import matplotlib
matplotlib.rcParams['figure.figsize'] = (15,12)
matplotlib.rcParams['xtick.labelsize'] = 35
matplotlib.rcParams['ytick.labelsize'] = 35
matplotlib.rcParams['font.size'] = 35
matplotlib.rcParams['axes.labelsize'] = 50
matplotlib.rcParams['axes.facecolor'] = 'white'
matplotlib.rcParams['axes.edgecolor'] = 'black'
matplotlib.rcParams['axes.linewidth'] = 5
matplotlib.rcParams['lines.linewidth'] = 10.0 # line width in points
matplotlib.rcParams['image.cmap'] = 'gray'
#matplotlib.rcParams['lines.color'] = 'blue' # has no affect on plot(); see axes.prop_cycle
matplotlib.rcParams['lines.markersize'] = 8 #

One guessing game, called “squeezed”, is very common in parties. It consists of a player, the chooser, who writes down a number between 00–99. The other players then take turns guessing numbers, with a catch: if one says the chosen number, he loses and has to do something daft. If the guessed number is not the chosen one, it splits the range. The chooser then states the part which contains the chosen number. If the new region only has one number, the chooser is said to be “squeezed” and is punished. An example of gameplay would be:

Chooser writes down (secretly) his number (let’s say, 30).

- Chooser: “State a number between 00 and 99.”
- Player: “42”.
- Chooser: “State a number between 00 and 42.”
- Player: “26”.
Chooser: “State a number between 26 and 42.”

$\vdots$

Chooser: “State a number between 29 and 32.”

- Player: “31”.

- Chooser dances some very silly children song.

Implement this game in Python, where the computer is the chooser.

**Useful:** $\mathtt{random.randint()}$ and $\mathtt{input()}$.

Given the following lists:

```
In [ ]:
```numbers = [[1,2,3],[4,5,6],[7,8,9]]
words = ['if','i','could','just','go','outside','and','have','an','ice','cream']

- 'numbers' is a list of lists. Using a list comprehension, flatten 'numbers' so it is a list of only numbers (not list of lists).
- use the newly flattened 'numbers' and filter it in a way that it only contains odd numbers.
- using a list comprehension, remove all words containing an 'i' from 'words'
- using a list comprehension, remove all words containing more than two vowels from 'words'.
- find all prime numbers between 1 and 100 using a single list comprehension

Points may be given in polar $(r, \theta)$ or cartesian coordinates $(x, y)$, see Figure 1.

Figure 1. Relationship between polar and cartesian coordinates.

such that they can in addition handle lists of tuples.

Draw $N=10000$ unifromly distributed random numbers (use `np.random.uniform`

, for example). Plot it's histogram and check that it looks uniform.

Now draw another such sample, and sum the two. How does the histogram of the sum look like?

Continue to sum $3,4,5,..$ such samples and keep plotting the histogram. It should quickly start to look like a gaussian.

This is a quite famous optical illusion:

The rows are perfectly straight, althought they appear crooked. Use numpy and slicing operations to verify for yourself that they are indeed so.

The code for loading the image as a numpy array is provided below:

```
In [2]:
```import scipy.ndimage
im = scipy.ndimage.imread("images/ill.png")
plt.imshow(im)
plt.grid(0)
plt.axis('Off')

```
Out[2]:
```

```
In [3]:
```x = np.arange(-1,1, 0.01)
y = np.arange(-1,1, 0.01)
X,Y = np.meshgrid(x,y)
Z = X**2 + Y**2
Z = np.where(Z<1, 1, 0)
plt.matshow(Z)

```
Out[3]:
```

Convert this image:

to

```
In [4]:
```mos = scipy.ndimage.imread("images/mosaic_grey.png")
plt.imshow(mos)

```
Out[4]:
```