I am currently working on a class project, and it deals with user-defined functions.
I had to get the grid size of an array and put them in a list, as [row, columns], and then there is another function where they check by putting random integers in another list to see if that certain position is inside the array or not. For example, if I have an array with 3 rows and 4 columns, it would be [3,4] and during the test, I inserted [4,4] it would return as false. I am not allowed to hardcore the "position" variable, and that is the one where a list of two integers will be given to compare to the actual size of the array.
What should I do?
Here is my current code
def get_grid_size(grid: list[list[str]]) -> list[int, int]:
grid_size = load_map(MAP_FILE)
col = len(grid_size[0])
row = len(grid_size)
grid_size = [row,col]
return grid_size
def is_inside_grid(grid: list[list[str]], position: list[int, int]) -> bool:
given_row = int(position[1])
given_col = int(position[0])
grid_rows, grid_cols = get_grid_size(grid)
print(grid_rows, grid_cols)
while True:
if grid_rows >= given_row and grid_cols >= given_col:
return True
else:
return False
I tried getting the 0th and 1sth index and respectively make them as row and column variable, then checked weather or now those position row and position column integers were smaller or equal to the actual array row and array column, if it was smaller or equal to, then yes its inside the grid, if its bigger, its not. Negative integers will not be tested for.