# Calculating total score with addition and subtraction of points based on recall

Hello everyone,

I am new to Psychopy and have a question regarding if this function would be possible via coding.

The experiment so far shows participants words that appear on the screen one at a time, then participants rate the likelihood they will remember the word using a rater scale (1-9). After all words are shown and rated by the participant, they then enter the recall stage and type out however many words they recalled.

I want to award them points based on their rated scores but only if they actually recalled the item. That is, if they rated the likelihood that they would remember the word â€śdogâ€ť as a 7, and entered the word â€śdogâ€ť into the recall section, I would want them to receive 7 points toward their total score that would appear at the end of the trial. Alternatively, if they fail to recall an item, I would want them to lose the amount of points they rated for the word they forgot.

Is there a way to display a â€śtotal scoreâ€ť for this type of calculation?

This is a good use case for Python dictionaries, which allow you to associate a key (in this case a word) with a value (in this case, the rating).

e.g. initialise it like this:

``````word_rating = dict() # empty dictionary
``````

Then for each rated word, store it with its associated rating like this:

``````word_rating[word] = rating
``````

which will end up looking like this:

``````{'dog': 7, 'cat': 2} # etc
``````

Then at the end, you will create a list of the words typed out by the subject. You cycle through that list, see if that word is in the dictionary, and if so, add its rating to the total:

``````total = 0

for response in response_list:
if response in word_rating.keys:
total = total + word_rating[response]
``````
1 Like

Hi @Michael,

Thank you for your response!

I am a little confused because I am using the builder and currently have each word on a loop that is being read from an Excel sheet. Would these codes be placed in the coding properties thatâ€™s accessed through the custom option of the components tab?

I am also a little unsure how to access the actual stored rating of what the participants respond with. Am I on the right track by using something like this to retrieve the ratings?:

rating = ratingScale.getRating()

Thank you in advance!

You used the â€ścodingâ€ť rather than â€śBuilderâ€ť tag for your post, so yes, that answer assumed that you were in control of everything via code. But the principles are the same.

Yes indeed. You just need to be careful to put code in the right tab of that code component, so it gets executed at the right time. e.g. in the â€śBegin experimentâ€ť tab, only put code that should be executed just once:

``````word_ratings = dict() # empty dictionary
``````

I guess so, Iâ€™m not that familiar with the rating scale. If so, then put something like this in the â€śend routineâ€ť tab:

``````word_ratings[word] = ratingScale.getRating()
``````

where you replace `word` with whatever the actual column name is you are using in your conditions file to hold the word for each trial.

The most complicated bit for you will be having a routine where you gather typed responses from the subject, but there are quite a few posts on this forum that will explain how to do that.