from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'bayesian_quiz' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): question_1 = models.IntegerField( choices=[['1', '80/100'], ['2', '15/100'], ['3', '(15/100)*(80/100)'], ['4', '(15*80)/(85*20+15*80)']], label='A witness sees a crime involving a taxi in a city. The witness says that the taxi is blue. It ' \ 'is known from previous research that witnesses are correct 80% of the time when making such statements. ' \ 'The police also know that 15% of the taxis in the city are blue, the other 85% being green. What is ' \ 'the probability that a blue taxi was involved in the crime?', widget=widgets.RadioSelect ) question_2 = models.IntegerField( choices=[['1', 'They are not independent, since there is a Queen of diamonds.'], ['2', 'Only when we first get a card to see if it is a diamond, return the card to the pack and ' 'then get a second card to see if it is a Queen.'], ['3', 'They are independent, since P(Queen of diamonds)=P(Queen)xP(diamonds).'], ['4', 'They are not independent, since P(Queen/diamonds)=P(Queen)']], label='A deck of playing cards has 52 cards. There are four suits (clubs, diamonds, hearts, and spades), ' 'each of which has thirteen numbered cards (2,...,9,Jack,Queen,King,Ace). We pick a card up at random. ' 'Let A be the event `getting diamonds` and B the event `getting a Queen`. Are events A and B independent?', widget=widgets.RadioSelect ) question_3 = models.IntegerField( choices=[['1', 'The second lamp is more likely to be defective.'], ['2', 'The second lamp is most likely to be correct.'], ['3', 'The probabilities for the second lamp being either correct or defective are the same.']], label='There are four lamps in a box, two of which are defective. We pick up two lamps at random from the box,' 'one after another, without replacement. Given that the first lamp was defective:', widget=widgets.RadioSelect ) question_4 = models.IntegerField( choices=[['1', 'The player will win the first set.'], ['2', 'The player will win the first set but lose the match.'], ['3', 'Both events are equally likely.']], label='Suppose a tennis player reaches the U.S. Open final. He has to win 3 out of 5 sets to win the final. ' 'Which of the following events are more likely?', widget=widgets.RadioSelect ) question_5 = models.IntegerField( choices=[['1', 'An unhappy marriage will result in divorce.'], ['2', 'A divorce is the result of an unhappy marriage.'], ['3', 'The two events are equally likely']], label='In which of the following statements do you have the most confidence?', widget=widgets.RadioSelect ) question_6 = models.IntegerField( choices=[['1', '1/2'], ['2', '1/6'], ['3', '1/3'], ['4', '1/4']], label='Two black marbles and two white marbles are put in an urn. We pick a white marble from the urn. ' 'Then, without putting the white marble in the urn again, we pick a second marble from the urn. If the ' 'first marble is white, what is the probability that the second marble is white?', widget=widgets.RadioSelect ) question_7 = models.IntegerField( choices=[['1', 'Getting two red marbles.'], ['2', 'The first marble is red and the second is blue.'], ['3', 'The two events are equally likely.']], label='An urn contains one blue marble and two red marbles. We pick up two marbles at random, one after ' 'another without replacement. Which of the events is more likely?', widget=widgets.RadioSelect ) question_8 = models.IntegerField( choices=[['1', '1/6'], ['2', '1/12'], ['3', '1/24'], ['4', '1/36']], label='In throwing two six-sided dice (numbered 1,...,6) the sum of the two numbers showing was 12. What ' 'is the probability of this occurring?', widget=widgets.RadioSelect ) question_9 = models.IntegerField( choices=[['1', '2/3'], ['2', '1/2'], ['3', '1/4'], ['4', '1/6']], label='A person throws a six-sided dice (numbered 1,...,6) repeatedly. The dice is fair (all the numbers are ' 'equally likely). The results of the first 10 throws are ' 'Odd, even, even, odd, odd, even, odd, odd, even, even. The person throws once more. What is the ' 'probability to get an odd number this time?', widget=widgets.RadioSelect ) question_10 = models.IntegerField( choices=[['1', '0.8+0.7'], ['2', '0.8-0.7'], ['3', '0.8*0.7'], ['4', '0.8/0.7']], label='A group of students in school take a mathematics test and an English test. 80% of students pass the ' 'mathematics test and 70% of the students pass the English test. Assuming the two subjects score ' 'independently, what is the probability that a student passes both tests (mathematics and English)?', widget=widgets.RadioSelect ) correct_answers = models.IntegerField(initial=0) # PAGES class Waiting(Page): pass class Introduction(Page): pass class Quiz(Page): timeout_seconds = 600 form_model = 'player' form_fields = ['question_1', 'question_2', 'question_3', 'question_4', 'question_5', 'question_6', 'question_7', 'question_8', 'question_9', 'question_10'] class Results(Page): @staticmethod def before_next_page(player: Player, timeout_happened): if player.question_1 == 4: player.correct_answers += 1 if player.question_2 == 1: player.correct_answers += 1 if player.question_3 == 2: player.correct_answers += 1 if player.question_4 == 1: player.correct_answers += 1 if player.question_5 == 2: player.correct_answers += 1 if player.question_6 == 3: player.correct_answers += 1 if player.question_7 == 3: player.correct_answers += 1 if player.question_8 == 4: player.correct_answers += 1 if player.question_9 == 2: player.correct_answers += 1 if player.question_10 == 3: player.correct_answers += 1 participant = player.participant participant.quiz_correct_answers = player.correct_answers class ResultsWaitPage(WaitPage): pass page_sequence = [Waiting, Introduction, Quiz, Results, ResultsWaitPage]