首页 > 编程知识 正文

python怎么设置计数器,python中计数器的用法

时间:2023-05-05 00:21:42 阅读:277872 作者:1040

我试图在Otree(Python库)中实现一个简单的计分器,通过修改竞猜游戏模板使之成为两个玩家。在

最后,我希望这个计数器只在某些情况下更新,但现在,我只想在每一轮之后增加10个。在

在模型.py,我定义了如下播放器类:class Player(BasePlayer):

question_id = models.IntegerField()

confidence = models.FloatField(widget=widgets.Slider(attrs={'step': '0.01'}))

question = models.StringField()

solution = models.StringField()

submitted_answer = models.StringField(widget=widgets.RadioSelect)

is_correct = models.BooleanField()

total_score = models.IntegerField(initial = 0)

def other_player(self):

return self.get_others_in_group()[0]

def current_question(self):

return self.session.vars['questions'][self.round_number - 1]

def check_correct(self):

self.is_correct = self.submitted_answer == self.solution

def check_if_awarded_points(self):

self.get_others_in_group()[0].submitted_answer == self.submitted_answer == self.solution

def score_points(self):

self.total_score+=10

self.payoff += c(10)

上面唯一相关的函数是“score points”,我在页面.py模板如下:

^{pr2}$

然后我创建一个结果页面,在每个问题后显示测试结果,以测试“总成绩”或“回报”是否每题增加10。在class IntermediateResults(Page):

def vars_for_template(self):

return {

'total_score': [p.total_score for p in self.group.get_players()],

'total_payoff': [p.payoff for p in self.group.get_players()]

}

如果我使用Django暴露total_payoff和total_score的值,我会看到它们的值是10,并且永远不会改变。我不知道为什么会这样。有什么想法吗?在

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。