Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. #I attempted to write a code

#Imagine that the user specifies with width and height of a grid, and provides a tile in that grid. #I attempted to write a code using if-else statements to return all of the tiles adjacent to the tile provided by the user in string format separated by spaces. There should be an additional space at the end of the string that the computer will return.THIS WAS AN EXAMPLE GIVEN IN CLASS but it has errors when running the test cases. #For example, on the 7x10 grid.tiles 24 has the neighbors "16 17 18 23 25 30 31 32 ". If a tile is at the edge of the grid, such as tile 64, we only include its adjacent neighbors ("57 58 65 "). Make sure the tiles return in sorted order like in a string.

image text in transcribed

image text in transcribed

Write code in Python 2.7 1 def findNeighbors (width, height, tile): 2 width - width height - height tile tile #main reference tile number 24 row - (tile - 1) // width col = (tile - 1) % width 4 top - tile - width top lfttop - 1 top rt top 1 lft-tile - :1 rt - tile 1 bottomtile width btm lft-bottom - 1 btm rtbottom 1 result-" " if(row -1)2) and (col-1)28): 10 12 13 14 15 16 17 18 19 20 21 23 24 25 26 27 28 29 30 31 32 if(row-1)se): if (row - 1 >-8) and (col + 1 = 0): #same row as reference tile if(col +1)se): if (row + 1 )s e) and (col - 1 = ): if (row + 1 >= ) : if (row + 1 > 0) and (col + 1 -8) and (col + 1 = 0): #same row as reference tile if(col +1)se): if (row + 1 )s e) and (col - 1 = ): if (row + 1 >= ) : if (row + 1 > 0) and (col + 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions