首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Otree计数错误

使用Otree计数错误
EN

Stack Overflow用户
提问于 2020-03-12 01:02:44
回答 1查看 169关注 0票数 0

我试图在Otree中创建一个简单的计数器,当我没有0树形式的正确答案时,它会给出一条信息,并且在一个被试得到正确答案之前,我还会计算出他/她所做的尝试总数(我试图计算每个问题中每个主题的错误)。

我有下一个代码,但是当有人出错时,这段代码不会在表单中添加任何内容。

代码语言:javascript
复制
class CRT1(Page):
   #def is_displayed(self):
   #return self.player.tipo == 1

form_model = 'player'
form_fields = ['CRT1', 'incorrect_attempts1']

def CRT1_error_message(self, values):
    print('Escogiste', values)
    if values != 2:
        return 'No lo olvides, sólo la respuesta seleccionada por el mayor número de los participantes en una sesión es la más seleccionada.'
        self.player.incorrect_attempts1 += 1
        print(incorrect_attempts1

如果有人能给出如何使这段代码工作的想法,那就太好了,谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-12 02:01:59

您在添加到计数器之前返回。要这样做:

代码语言:javascript
复制
def CRT1_error_message(self, values):
    print('Escogiste', values)
    if values != 2:

        self.player.incorrect_attempts1 += 1
        return 'No lo olvides, sólo la respuesta seleccionada por el mayor número de los participantes en una sesión es la más seleccionada.'

确保incorrect_attempts1initial=0

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60646339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档