+ 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])

1st Jan 2022, 11:12 PM
Ephraim Darkey
Ephraim Darkey - avatar
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
1st Jan 2022, 11:23 PM
rodwynnejones
rodwynnejones - avatar
+ 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])
2nd Jan 2022, 12:24 AM
Brian
Brian - avatar