Jack Reed
Jack Reed

Reputation: 23

Quiz that I made in python won't work

I have recently made a quiz in my computer science lesson but for some reason it did not work, I am new to programming and I was wondering maybe you could help me, I know that it will be something simple but as I said, I am new to this. I have only copied 4 questions out of the 8 I have made but for some reason it ignores the IF statement and goes straight to the else statement. The code is the following:

score=0
print("Welcome the the general knowledge quiz")
your_name = input("What is your name?: ")

input("Press Enter to Start the Quiz!")

print("1) Who presents Pointless?")
answer = input()
if answer == ["Alexander Armstong", "alexander armstrong", "ALEXANDER  
ARMSTRONG"]:
    print("Well done", your_name)
    score = score+1
else:
    print("Sorry, the answer was Alexander Armstrong")
print("Your score is", score)


print("2) Who presents I'm a celeb, get me out of here?")
answer = input()
if answer == ["Ant and Dec", "ant and dec", "ANT AND DEC", "Ant And Dec"]:
    print("Well done", your_name)
    score = score+1
else:
    print("Sorry, the answer was Ant and Dec")
print("Your score is", score)


print("3) What is the capital of England?")
answer = input()
if answer == ["London", "london", "LONDON"]:
    print("Well done", your_name)
    score = score+1
else:
    print("Sorry, the answer was London")
print("Your score is", score)


print("4) Who lives on the White house right now?")
answer = input()
if answer == ["Obama", "obama", "Barack Obama", "barack obama"]:
    print("Well done", your_name)
    score = score+1
else:
    print("Sorry, the answer was Barack Obama")
print("Your score is", score)

Upvotes: 2

Views: 97

Answers (2)

user3030010
user3030010

Reputation: 1867

answer = input()
if answer == ["Alexander Armstong", "alexander armstrong", "ALEXANDER  
ARMSTRONG ):

Missing quotation mark aside, this if statement will always fail. input() always returns a string, but you're checking if it's equal to a list, which can never be true. If you replace == with in, it will do what you expect.

Also, you should consider using .lower() to make the answer into lowercase, then you'd only have one value to check.

Upvotes: 5

Jack Deeth
Jack Deeth

Reputation: 3357

There's a hint in the syntax highlighting: you're missing a ":

if answer == ["Alexander Armstong", "alexander armstrong", "ALEXANDER ARMSTRONG ):
    print("Well done", your_name)

There's no " after ARMSTRONG.

Upvotes: 1

Related Questions