Update grid.py

i have made this code into a loop instead of constant print lines and i have also made this code into a small function