Hi All,
I am currently trying to build a multiple choice quiz(Guess the capital cities).
To do so I have created a class called Question which has to two attributes:
- the question
- the answer.
I have then created a variable = to this class which stores the answers to the above class.
I have then created. a function to loop through each question however this does not appear to be working.
2 issues:
- The questions don’t appear on individual lines.
- It doesn’t appear to be registering the questions in function.
I have attached screenshot also.
any advice welcome!
please see my code:
- from classes import Question
- question_prompts = [
-
“What is the capital of France?\na. Paris \nb. Nice \nc. Lille\n\n”,
-
“What is the capital of Germany?\na. Munich \nb. Berlin \nc. Frankfurt\n\n”,
-
“What is the capital of Jamaica?\na.Portmore \nb.Montego Bay \nc. Kingston\n\n”,
-
"What is the capital of Poland?\na.Warsaw \nb.Krakow \nc.Sopot\n\n ",
-
“What is the capital of Brasil?\na.Brasilia \nb.Rio de janeiro \nc.Sao Paulo\n\n”,
-
“What is the capital of South Africa?\na.Cape town \nb.Pretoria \nc.Johannesburg\n\n”,
-
“What is the capital of Kenya?\na.Mombasa \nb.Nairobi \nc.Malindi\n\n”,
-
“What is the capital of Spain?\na.Barcelona \nb.Madrid \nc.Valencia\n\n”,
-
“What is the capital of Italy?\na.Naples \nb.Milan \nc.Rome\n\n”,
-
“What is the capital of India?\na.New Delhi \nb.Mumbai \ncBangalore\n\n”,
-
]
- questions = [
-
Question(question_prompts[0], “a”),
-
Question(question_prompts[1], “a”),
-
Question(question_prompts[2], “c”),
-
Question(question_prompts[3], “a”),
-
Question(question_prompts[4], “a”),
-
Question(question_prompts[5], “a”),
-
Question(question_prompts[6], “b”),
-
Question(question_prompts[7], “b”),
-
Question(question_prompts[8], “c”),
-
Question(question_prompts[9], “a”),
-
]
-
def run_test(questions):
-
score = 0
-
for question in questions:
-
answer = input(question_prompts)
-
if answer == question.answer:
-
score += 1
-
print(" You got " + str(score) + “/” + str(len(questions)) + “correct”)
- run_test(questions)