Click here to Skip to main content
15,305,577 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#this is the code below
print(input("Choose a tile: "))

list = ["y1", "y5", "y9", "d1"]
list2 = ["z1", "y8", "d2", "f2"]

if input[list]

if input[list2]

# and this is the error it gives me
 if input[list]
SyntaxError: invalid syntax

What I have tried:

i tried using elif and tried writing list2 without the brackets
Updated 29-Jan-21 6:17am
CHill60 29-Jan-21 11:42am
What are you trying to achieve?

1 solution

An if statement must be terminated by a colon (:), and the following lines must be indented, thus:
if input[list]:

if input[list2]:

However, that code makes no sense, see Built-in Functions — Python 3.7.9 documentation[^].

corrected text above. : is a colon.
Richard Deeming 29-Jan-21 12:31pm
That's not a semi-colon. :)

: = colon
; = semi-colon
Richard MacCutchan 29-Jan-21 12:37pm
Why on earth did I write that? doh!
CPallini 29-Jan-21 13:44pm
Being C-hearted, you immediately associated 'semicolon' to 'terminator'.
My 5.
Richard MacCutchan 30-Jan-21 4:24am
Thanks Carlo, generous as always.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900