Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please use the python language, preferabally 2.7 for this, and you will be const

ID: 3874411 • Letter: P

Question

please use the python language, preferabally 2.7 for this, and you will be constructing if-elif-else statement to meet the condition of the tile that the grid would be asking. Please be sure it would work for all inputs.   The parameters and answer template for the solution is also given beneath the screenshot below

Here below is answer template and parameter for this problem.

def getCorner(width, height):
    width = width
    height = height


    #YOUR CODE GOES HERE (indented)

  
    #END YOUR CODE

Imagine that the user specifies with width and height ofa grid. You will return a string that represents all ordered tiles that make up the corners of the grid, with three tiles to a corner. You will return a string where each tile has a space after it (this will simplify your algorithm). For example, on a 7x10 grid, 14 25 26 57 63 64 65 69 70 you would return the string "12678 14 57 63 64 65 69 70 ". If the board doesn't have a width or height of at least four, you should return the tiles of all the edges. Under such cases, you want to avoid putting duplicate tiles in your strings, to do this, use the python in boolean expression: -12" in "11 12 13 "would return True, while e in "11 12 13 "would return False.

Explanation / Answer

Python 2.7 code:

def getCorner(width, heigth):
mystr= ""
matrix = []
tile_value = 1
for i in range(0,heigth):
   row = []
   for j in range(0,width):
     row.append(tile_value)
     tile_value = tile_value + 1
   matrix.append(row)
if(width >=4 and heigth >= 4):
  mystr += str((matrix[0][0])); mystr += " ";mystr += str(matrix[0][1]);mystr += " ";
  mystr += str(matrix[0][width-2]);mystr += " ";mystr += str(matrix[0][width-1]);mystr += " ";
  mystr += str(matrix[1][0]);mystr += " ";mystr += str(matrix[1][width-1]);mystr += " ";
  mystr += str(matrix[heigth-2][0]);mystr += " ";mystr += str(matrix[heigth-2][width-1]);mystr += " ";
  mystr += str(matrix[heigth-1][0]);mystr += " ";mystr += str(matrix[heigth-1][1]);mystr += " ";
  mystr += str(matrix[heigth-1][width-2]);mystr += " ";mystr += str(matrix[heigth-1][width-1]);mystr += " ";
elif(width<=0 or heigth <= 0):
  return "Invalid width or heigth, both heigth and widht must > 0"
else:
  mystr += str((matrix[0][0])); mystr += " ";
  if(str(matrix[0][width-1]) not in mystr):
   mystr += str(matrix[0][width-1]);mystr += " ";
  if(str((matrix[heigth - 1][0])) not in mystr):
   mystr += str((matrix[heigth - 1][0])); mystr += " ";
  if(str(matrix[heigth - 1][width-1]) not in mystr):
   mystr += str(matrix[heigth - 1][width-1]);mystr += " ";  
return mystr

print getCorner(7,10)

Sample Output:

1)

print getCorner(7,10)

1 2 6 7 8 14 57 63 64 65 69 70

2)

print getCorner(4,4)

1 2 3 4 5 8 9 12 13 14 15 16

3)

print getCorner(4,2)

1 4 5 8