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

python In order to allow the user to select a point, you will need to display a

ID: 3666058 • Letter: P

Question

python

In order to allow the user to select a point, you will need to display a grid (fixed size is 5 rows by 5 columns) with unique symbols (I used the alphabet). The user will select one of the symbols. Then you will display two perpendicular lines (use asterisks *) that go through the point selected (see sample execution). The only stipulations are that the asterisks used to display the lines must be stored in a 2 dimensional (nested) list and that you have at least 2 functions.

I know how to build the 5x5 matix but not sure how to match the user input to an element of the matrix and match it with the rows and colums that include that character and replace it with asterisks

Explanation / Answer

Hi, I have written the following program for the given problem statement. It has two functions, one main driver function and second one to display the perpendicular lines. As asked, asterisks have been stored in a 2-dimensional netsed list.

#Program to let the user select a point and display perpendicular lines there


#Function to display perpendicular lines using asterisks
def dispLines(i, j):

   #Nested list to store the asterisks
   ast = [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']]
  
   #print the lines at the point selected
   for a in range(len(ast)):
       for b in range(len(ast[a])):
           if(a == i) or (b == j):
               print ast[a][b],
           else:
               print ' ',
       print

#main driver function
def main():

   #Grid to store the unique symbols
   Grid = [['A', 'B', 'C', 'D', 'E'], ['F', 'G', 'H', 'I', 'J'], ['K', 'L', 'M', 'N', 'O'], ['P', 'Q', 'R', 'S', 'T'], ['U', 'V', 'W', 'X', 'Y']]

   #Display the grid
   for i in range(len(Grid)):
       for j in range(len(Grid[i])):
           print Grid[i][j],
       print

   #Prompt the user for selection
   alpha = raw_input('Select an alphabet: ')

   #Matching the user input with the grid symbols
   for i in range(len(Grid)):
       for j in range(len(Grid[i])):
           if(alpha == Grid[i][j]):
               break
       if(alpha == Grid[i][j]):
           break

   dispLines(i, j)

main()

Let me know if you don't get something.