In a modify task you take code that is nearly there and adapt it so that it does what it should.
A cinema stores its seating plan in a 2D array. Each row of the array is a row
of seats. "X" is a seat that has been booked and "O" is an empty seat.
A programmer has started a program that lets the staff check one seat: they enter the row number and then the column number, and the program says whether that seat is booked. The editor starts you off with their code:
seats = [
["X", "O", "O", "X"],
["O", "O", "X", "O"],
["X", "X", "O", "O"]
]
print("Enter row (0-2):")
r = int(input())
print("Enter column (0-3):")
c = int(input())
status = seats[c][r]
if status == "??????":
print("??????")
else:
print("??????")
It does not work yet. The indices on the status line are in the wrong order,
so the program looks up the wrong seat, and for the last column it crashes. The
?????? parts are placeholders the programmer never filled in.
Modify the program so that it:
Leave the array and the two questions exactly as they are.
The two questions come first, exactly as they are in the starter code:
Enter row (0-2):
Enter column (0-3):
Then one line. For a booked seat ("X") it reads:
That seat is booked
and for an empty seat ("O") it reads:
That seat is empty
Input:
0
3
Output:
Enter row (0-2):
Enter column (0-3):
That seat is booked
Input:
0
2
Output:
Enter row (0-2):
Enter column (0-3):
That seat is empty
Row 0, column 2 is the third seat on the front row. The starter code looks up row 2, column 0 instead, which is booked.
Both questions are part of the output that is checked here, so their spelling,
capital letters and punctuation count. Keep each one in its own print, with a
bare input() on the next line.
Make sure that you check for the following things:
seats[r][c].if compares with "X" or "O" in capitals, inside speech marks.?????? has been replaced, and the two messages match the ones above
exactly.