You can replace all of this by first doing

```python
import random
```

and then

```python
polygons.append(Polygon(random.choice(shapes)))
```