Use the programming language python to solve the following task You and your neighbor both have equally sized gardens. The gardens are represented as 2D lists, where the garden [i] [j], gives an element to the position (i, j). Each element of a garden is represented as a string, and can be any of the following: "grass", "moss", "strawberry", "rock", "raspberry". You have recently seen that there has been a lot of moss and stone in your garden, and suspect that it is your neighbor who has put it there. To fix this, complete the clean_garden (my_garden, neighbors_garden) function. Here you will first create small functions to make it easier to solve the actual task. Create a function find_item that takes in two arguments: (garden, item), which returns an (i, j) position as a tuple, whose item is in the garden. If it does not exist, return None Create a function swap_items that exchanges two elements between two gardens, let it take in these arguments: (garden1, garden2, pos1, pos2), where pos1 and pos2 are (i, j) doubles. Here you should not return anything, but change the lists you receive as arguments. Use the functions you have defined to complete clean_garden (my_garden, neighbors_garden): Replace all "rock" with "strawberry", and "moss" with "raspberry" from your neighbor's garden as long as there are opportunities for exchange.
Use the programming language python to solve the following task
You and your neighbor both have equally sized gardens. The gardens are represented as 2D lists, where the garden [i] [j], gives an element to the position (i, j). Each element of a garden is represented as a string, and can be any of the following: "grass", "moss", "strawberry", "rock", "raspberry". You have recently seen that there has been a lot of moss and stone in your garden, and suspect that it is your neighbor who has put it there. To fix this, complete the clean_garden (my_garden, neighbors_garden) function. Here you will first create small functions to make it easier to solve the actual task.
Create a function find_item that takes in two arguments: (garden, item), which returns an (i, j) position as a tuple, whose item is in the garden. If it does not exist, return None
Create a function swap_items that exchanges two elements between two gardens, let it take in these arguments: (garden1, garden2, pos1, pos2), where pos1 and pos2 are (i, j) doubles. Here you should not return anything, but change the lists you receive as arguments.
Use the functions you have defined to complete clean_garden (my_garden, neighbors_garden): Replace all "rock" with "strawberry", and "moss" with "raspberry" from your neighbor's garden as long as there are opportunities for exchange.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images