2

I have been writing a simple quiz with python but keep getting a "SyntaxError: multiple statements found while compiling a single statement" in my Python GUI. Please help.

print("Welcome to my quiz!")
score = 0
question1 = str(input("What colour is a banana."))
if question.lower() == 'yellow':
 print("Correct. The answer is", question1)
 score = score + 1
else:
 print("Incorrect. The answer is yellow, not", question1)
print score
asked Apr 2, 2013 at 23:40
0

2 Answers 2

8

You've got a couple issues. First, question is not defined (line 4); that should be question1. Second, print is a function in Python 3, so your last line ought to be print(score). Third, input already returns a string, so you don't need the str call. So line 3 ought to look like this:

question1 = input("What colour is a banana.")
answered Apr 2, 2013 at 23:43
Sign up to request clarification or add additional context in comments.

2 Comments

There is no raw_input in python 3.
@PavelAnossov Oh, heck. That's what I get for posting on a Py3 question without Py3 installed. Fixed :)
0

This is a more advanced version of your program but by using a list we can do it easier

 print("Welcome to my quiz!")
score = 0 
color = ['yellow']
question1 = str(input("What colour is a banana."))
if question1 == color[0]:
 print("Correct. The answer is", question1)
 score +=1
 print(score)
else:
 print("Incorrect. The answer is yellow, not", question1)
 
 print (score)
answered Dec 15, 2022 at 20:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.