Understand the field: Recognise that the field is a nested list of lists where each element can be accessed using row and column indexes.
Plan the path: On even rows (0, 2, 4, ...), the tractor should move from left to right. On odd rows (1, 3, 5, ...), it should move from right to left.
Implement the Logic: Use loops and conditions to build the path according to the above plan.
Reuse the reverse_list function: Change the direction of the tractor by reusing code.
Return the movements: Your function should ultimately return a list of tuples, with each tuple representing the coordinates (row, column) of each movement.
Will this function:
def reverse_list(input_list):
list_reversed = input_list[::-1]
return list_reversed
def student_function(field):
plough_movements = []
for row_index, row in enumerate(field):
if row_index % 2 == 0:
plough_movements.extend([(col, row_index) for col in range(len(row))])
else:
reverse_row = reverse_list(row)
plough_movements.extend([(col, row_index) for col in range(len(reverse_row))])
return plough_movements
give this result:
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (3, 4), (3, 3), (3, 2), (3, 1), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (5, 4), (5, 3), (5, 2), (5, 1), (5, 0), (6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (7, 4), (7, 3), (7, 2), (7, 1), (7, 0), (8, 0), (8, 1), (8, 2), (8, 3), (8, 4), (9, 4), (9, 3), (9, 2), (9, 1), (9, 0)]
If you try to learn python you generally should not outsource your assignments to stackoverflow, but if i understood this question correctly, this should work:
Also please provide some context on what the field is exactly.