This block should be in a main() function which is called inside of the coditional.

```python
if __name__ == '__main__':
    main()
```

As it is, you are adding variables to global scope.