Hello Sorry if this is confusing I'm really new to python and have been stuck trying to figure this out for hours now.
I'm trying to write a function for a text based battlship game. I need the function to do this is_occupied:
(int, int, int, int, list of list of strs) -> bool
The first to int's are suppose to refer to indices in the list of list of strings, same with the second 2 int's. The idea is to check the indices from range 1st set to 2nd set including themselves for a specific string element.
This is what I have so far the quoted out part was a different approach I took however so far both approaches have been unsuccessful.
def is_occupied(row1, col1, row2, col2, board): #row_1_col1 = board[row1],[col1] #row_2_col2 = board[row2],[col2] board = board r1 =[row1],[col1] r2 =[row2],[col2] if r1 >= r2: return True else: #if row_1_col1 >= row_2_col2: #return True #else: #for item in range(row_1_col1,row_2_col2): #if item != (VACANT): #return True #else: #return False for col in range(board(r1,r2)): for item in col: if not item == (VACANT): return True else: return False
Any help would be greatly appreciated I have also made some attemps to use multiple nested loops however I haven't got anything to work yet.