Jan-09-2020, 04:23 PM
Im self teaching python , trying to create a quiz but Im having a error on line 17 , im importing from from this code
Quote:Question.py
class Question: def__init__(self, prompt, answer): self.prompt = prompt self.answer = answerfor file
Quote:building a multiple choice quiz.py
from Question import Question question_promts = [ "What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n\n", "What color are Bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n" , "What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n" ] questions = [ Question(question_prompts[0],"a" ), Question(question_prompts[1],"c" ), Question(question_prompts[2],"b" ), ] def run_test(questions): score = 0 for question in questions answer = input(question.prompt) if answer == question.answer: score += 1 print("You got " + str(score) + "/" + str(len(questions)) + "correct") run_test(questions)However it keeps telling me that I have a syntax error on line 17 when I run the program.
Traceback (most recent call last): File "/data/user/0/ru.iiec.pyroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile.mainpyfile) File "/data/user/0/ru.iiec.pyroid2/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(). __main__.__dict__) File "<string>", line 17 for question in questions ^ SyntaxError: invalid syntax [Program finished]