oTree Forum >

Send tailored error message?

#1 by R800377803

Hi All,

I have an 4 question quiz at the beginning of my experiment. I currently have it set up to give an error message if one or more responses are wrong.
 
Any idea how I would modify this to send a tailored error message such as "response 3 is incorrect" or "responses 2 and 4 are incorrect"?

    @staticmethod
    def error_message(player: Player, values):
        solutions = dict(
                         Q1='True',
                         Q2='1700',
                         Q3='300',
                         Q4='1480')

        if values != solutions:
            return "One or more Answers were incorrect."

#2 by BonnEconLab

Sure.

Code like the following should work (not tested):

    @staticmethod
    def error_message(player, values):
        message = ""
        if values["Q1"] != solutions["Q1"]:
            message = message + "The answer to question 1 is incorrect. "
        if values["Q2"] != solutions["Q2"]:
            message = message + "The answer to question 2 is incorrect. "
        if values["Q3"] != solutions["Q3"]:
            message = message + "The answer to question 3 is incorrect. "
        if values["Q4"] != solutions["Q4"]:
            message = message + "The answer to question 4 is incorrect. "
        if values != solutions:
            return message

I am not sure, however, whether you should give such detailed feedback!

Question-level feedback makes it possible for participants to simply cycle through the different response options instead of actually figuring out why a particular response to the comprehension check is correct.

#3 by Daniel_Frey (edited )

You can return an error message below every question that was answered incorrectly:

    @staticmethod
    def error_message(player: Player, values):
        error_msg_dict = {}
        solutions = dict(
                         Q1='True',
                         Q2='1700',
                         Q3='300',
                         Q4='1480')

        for key, sol in solutions.items():
            if values[key] != sol:
                error_msg_dict[key] = "This question was answered incorrectly"
                
        return error_msg_dict

This code assumes that the keys in the solutions dictionary are the same as the formfields in the page.

I have used this myself in a project and it should work fine :)

Best,
Daniel

#4 by R800377803

Thanks Daniel, Thanks BonnEconLab, I haven't yet decided if I will use it...but appreciate the help!

#5 by R800377803

Thanks Daniel, Thanks BonnEconLab, I haven't yet decided if I will use it...but appreciate the help!

Write a reply

Set forum username