Hamodey_
Hamodey_

Reputation: 86

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.

Upvotes: 0

Views: 98

Answers (2)

aIKid
aIKid

Reputation: 28292

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")

Upvotes: 0

shad0w_wa1k3r
shad0w_wa1k3r

Reputation: 13372

  1. The input() has an unnecessary paranthesis in the beginning.
  2. The if statement is wrongly indented more.
  3. The elif doesn't have a :
  4. Imports must be made at the beginning.

Correct code

from random import choice
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']
        print(choice(list))

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

Upvotes: 0

Related Questions