Self taught , (creating a quiz) syntax error on my array - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Self taught , (creating a quiz) syntax error on my array (/thread-23633.html) |
Self taught , (creating a quiz) syntax error on my array - DarkAlchemyXEX - Jan-09-2020 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] RE: Self taught , (creating a quiz) syntax error on my array - Gribouillis - Jan-09-2020 I looks like a colon is missing at the end of the line... RE: Self taught , (creating a quiz) syntax error on my array - DarkAlchemyXEX - Jan-09-2020 I tried colon and I still receive the same syntax error only with a colon typed in RE: Self taught , (creating a quiz) syntax error on my array - michael1789 - Jan-09-2020 (Jan-09-2020, 05:52 PM)DarkAlchemyXEX Wrote: I tried colon and I still receive the same syntax error only with a colon typed in You need the colon. I ran it and you don't get the same error with it. RE: Self taught , (creating a quiz) syntax error on my array - DarkAlchemyXEX - Jan-09-2020 I deleted both files and decided to re-do the whole program , the good news is that Process finished with exit code 0 however nothing prints in the the terminal so the user cannot input naswers to the questions . This is what I have now. Quote:app.py from Question import Question question_prompts = [ "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" ] question = [ 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) Quote:Question.py class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer Process finished with exit code 0I noticed the error was fixed when my first attempt class Question: def__init__(self, prompt, answer):and second attempt def __init__(self, prompt, answer): self.prompt = promptI forgot to put a space between def and __init which was breaking the program . Again thank you all for helping I am learning this on my own and appreciate the input from everyone RE: Self taught , (creating a quiz) syntax error on my array - ichabod801 - Jan-09-2020 On line 23 questions is not defined. Is line 9 supposed to be questions instead of question? RE: Self taught , (creating a quiz) syntax error on my array - DarkAlchemyXEX - Jan-10-2020 I still get the same end result after the change ichabod801 RE: Self taught , (creating a quiz) syntax error on my array - ichabod801 - Jan-10-2020 You're also missing a colon at the end of line 19. It would really help if you would post the full text of the error messages you are getting. RE: Self taught , (creating a quiz) syntax error on my array - DarkAlchemyXEX - Jan-10-2020 C:\Users\Admin\PycharmProjects\Giraffe\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/Giraffe/Question.py Process finished with exit code 0im not getting any prompts to answer the question RE: Self taught , (creating a quiz) syntax error on my array - ichabod801 - Jan-10-2020 When I run your code with the fixes I have mentioned, it works. |