My code creates a "grid" of empty places, where 0 is used as the place holder, in a size specified by the user.
I was wondering if there were more efficient ways of doing this,or perhaps ways that make more aesthetically pleasing grids with less code.
My code is in working order and does as it says on the label, I also implemented a system that does not allow for incorrect inputs.
def gridSize_def():
global gridSize
while True:
try:
gridSize = int(input("input grid length and width\n"))
if gridSize<2:
print ("invalid int")
else:
break
except ValueError:
print ("invalid input")
grids = [[] for _ in range (gridSize)]
for i in range(0,gridSize):
grids[i-1]=[0 for _ in range(gridSize)]
return grids
def grid_def():
for i in range (0,gridSize):
print (grids[i-1])
grids = gridSize_def()
grid_def()
All feedback welcome!