Search code examples
pythonif-statementsyntax-error

Syntax error on simple IF.


Before you ask, I did look at other answers and questions they all seem to be the same and yes I did add it but still nothing. Okay, so I have a program with a menu and at the menu choice it keeps coming up with syntax error at the ":" colon, help please I have tried everything. Here's the code :

def main():
    print("Hello and Welcome to the 'Say When' program")

    print("1:Class\n2:Priamry\n3:Secondary\n4:FirstGag\n5:SecondGag")
    menu = (input("What would you like to search?: ")
            if menu == '1':
                print("You chose Class")
                list = ['Assault', 'Engineer', 'Support', 'Recon']
                from random import choice
                print(choice(list))

            elif menu == '2'
                print("nice")

Error = Syntax error then it highlights the ":" in red.


Solution

  • You're missing a closing parentheses on your input function, which you don't need at all.

    menu = input("What would you like to search?: ")
    

    Full fixed code:

    def main():
        print("Hello and Welcome to the 'Say When' program")
    
        print("1:Class\n2:Priamry\n3:Secondary\n4:FirstGag\n5:SecondGag")
        menu = input("What would you like to search?: ")
        if menu == '1':
            print("You chose Class")
            list = ['Assault', 'Engineer', 'Support', 'Recon']
            from random import choice
            print(choice(list))
    
        elif menu == '2':
            print("nice")