Fixed that ugly while loop and flush compatibility.

```python
print("x", flush=True)
```

isn't supported everywhere (e.g. my Debian reports it as error.)
As alternative you can use sys.stdout.flush() after every print.

And even though it works, using while-loops as C-like for loops ain't pretty.
There's `for i in range(x, y)` for that. Just some things that immediately caught my eye. :)