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
2 Answers 2
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
Henry Keiter
17.3k8 gold badges53 silver badges85 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Pavel Anossov
There is no
raw_input in python 3.Henry Keiter
@PavelAnossov Oh, heck. That's what I get for posting on a Py3 question without Py3 installed. Fixed :)
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
user20514897
Comments
lang-py