Write a program, that allows a user to input integer values and query a 2-dimensional array of size 9x9. Your program should then ask the user for a pair of coordinates,(x,y), separated by a space and return the value at the position specified by the given coordinates. For instance, 0 3 should return the value 7 (the value at row one, column four – bearing in mind that array indices start at zero). Assume that each integer is a single digit from 1 - 9. Enter -1 for either coordinate to end the program.
Sample I/O:
Enter an array:
359716482
867345912
413928675
398574126
546281739
172639548
984163257
621857394
735492861
Enter coordinates: 0 3
Value = 7
Enter coordinates: 5 5
Value = 9
Enter coordinates: 8 8
Value = 1
Enter coordinates: -1 -1
DONE
This is my code so far:
arr = input("Enter an array:\n")
coordinates = input("Enter coordinates:\n")
x = coordinates[:1]
y = coordinates[2:3]
while x!= -1 or x!= -1 :
x = coordinates[:1]
y = coordinates[2:3]
x = int(x),
y = int(y)
value = arr[x][y]
print("Value = "+ arr)
It is very rough. I understand what I need to do and I have an idea of how to do it but the actual programming I struggle with. my idea is to create a sentinal loop that exits once the user enters -1 for a coordinate. using a while loop we ask for coordinates and then cut the string to get the individual x and y coordinates then use it to find the number in the specified index.