+ 1
What is wrong with my code
seats = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'] ] row=int(input()) column=int(input()) if row==0 and column==0; print(seat[0][0]) if row=0 and column=1; print(seat[0][1])
2 Answers
+ 3
seats = [
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
['j', 'k', 'l']
]
row=int(input())
column=int(input())
if row==0 and column==0: # use colon not semi-colon
print(seats[0][0]) # use seats not seat
if row==0 and column==1: # use == not =, use colon not semi-colon
print(seats[0][1]) ## use seats not seat
+ 2
1. Wrong use of semicolons instead of colons
2. Second if statement is wrongly indented
3. Second if statement uses assignment operators instead of comparison operators
4. seats is misspelled as seat in both print statements
Advice:
Make the second if statement into an elif statement.
Better advice:
Do you know that you can use variables in array indices? If you replace the literal values with variables, then you get a general solution without any need for if statements.
row=int(input())
column=int(input())
print(seats[row][column])