I'm a total noob here so I would really appreciate your help.
How to make a quiz game which would calculate different scores for different answers, regardless of their position (e.g. first or last on the displayed list)?
Currently, I'm doing this by slicing which means answers should be in a fixed order, but I don't want to have fixed answers order (e.g. if I shuffle the answers, I want it to recognize my correct_answer or fair_answer no matter it's position in the displayed answers list.
Inside quiz_brain.py inside QuizBrain class, I'm doing this within check_answer method:
def check_answer(self, user_answer):
"""Check the answer from the user and assign it the appropriate score"""
points_awarded = 0
if user_answer == self.current_question.choices[0]:
points_awarded = 4
elif user_answer == self.current_question.choices[1]:
points_awarded = 3
elif user_answer == self.current_question.choices[2]:
points_awarded = 2
elif user_answer == self.current_question.choices[3]:
points_awarded = 1
self.score += points_awarded
return points_awarded
and my question structure looks like this:
question_data = [
{
"question": "Kada ugledaš djevojku, kako ćeš joj prići??",
"choices": {
"correct_choice": "Cititat ćeš joj omiljene stihove Zoke Bosanca.",
"good_choice": "Mala, dobro izgledaš. Ajmo na sok.",
"decent_choice": "Čija si ti, mala?",
"fair_choice": "Želiš li možda da zajedno popijemo neko pićence?",
}
},
{
"question": "Gdje ćeš izvesti djevojku na prvi spoj?",
"choices": {
"correct_choice": "U kvartovsku ćevabdžinicu, jest ću ćevape s lukom, kako i dolikuje.",
"good_choice": "U ZOO, da posjeti svoju familiju.",
"decent_choice": "Prošetat ćemo Maksimirom, možda se nešto i dogodi.",
"fair_choice": "Izvest ću ju na kavu.",
}
},
# Add more questions here
]
Git with my current code: https://github.com/KooMar22/KrkanQuiz