コード例 #1
0
ファイル: multi_direct.py プロジェクト: o2edu/mathmaker
    def __init__(self, numbers_to_use, **options):
        super().setup("minimal", **options)
        super().setup("numbers", nb=numbers_to_use, **options)
        super().setup("nb_variants", nb=numbers_to_use, **options)

        product = Product([self.nb1, self.nb2])
        self.product_str = product.printed
        self.result = product.evaluate()

        if self.context == 'mini_problem':
            super().setup("mini_problem_wording",
                          q_id=os.path.splitext(os.path.basename(__file__))[0],
                          **options)
コード例 #2
0
    def __init__(self, build_data, **options):
        super().setup("minimal", **options)
        super().setup("numbers", nb=build_data, **options)
        super().setup("nb_variants", nb=build_data, **options)
        self.transduration = 8
        if not is_integer(self.nb1) or not is_integer(self.nb2):
            self.transduration = 15

        product = Product([self.nb1, self.nb2])
        self.product_str = product.printed
        self.result = product.evaluate()

        if self.context == 'mini_problem':
            self.transduration = 25
            super().setup('mini_problem_wording',
                          q_id=os.path.splitext(os.path.basename(__file__))[0],
                          **options)
コード例 #3
0
    def __init__(self, numbers_to_use, **options):
        super().setup("minimal", **options)
        if self.variant == 'with_a_decimal':
            second_couple = shared.mc_source.next('int_deci_clever_pairs')
        elif self.variant == 'integers_only':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever_in=[4, 5])
        elif self.variant == 'fifths_series':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever=5,
                                                  union={
                                                      'table_name':
                                                      'int_deci_clever_pairs',
                                                      'clever': 5
                                                  })
        elif self.variant == 'quarters_series':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever=4,
                                                  union={
                                                      'table_name':
                                                      'int_deci_clever_pairs',
                                                      'clever': 4
                                                  })
        else:
            second_couple = shared.mc_source.next(
                'intpairs_2to500',
                clever_in=[4, 5, 10],
                union={'table_name': 'int_deci_clever_pairs'})

        # We shuffle the numbers in a special way
        if len(numbers_to_use) == 1:
            # There is only one number in addition to the 2 special ones
            # so either we put it in the first place, or in the middle
            # (not at the end, otherwise, the 2 special ones would be at the
            # two first places)
            special_ones = list(second_couple)
            random.shuffle(special_ones)
            all_nb = [list(numbers_to_use).pop(0), special_ones.pop(0)]
            random.shuffle(all_nb)
            all_nb += [special_ones.pop(0)]
        else:
            # It is assumed there are 2 numbers_to_use (so 4 altogether)
            # In order to avoid having the two "special" numbers in a row at
            # the two first places, we will shuffle all numbers in a special
            # way.
            if random.choice([True, False]):
                # In this case, the first number will NOT be from the "special"
                # ones, so no matter what follows
                nb_to_use = list(numbers_to_use)
                random.shuffle(nb_to_use)
                all_nb = [nb_to_use.pop(0)]
                remaining = nb_to_use + list(second_couple)
            else:
                # In this case, it will, so, at the second place we put a
                # number from the other source (the user specified one)
                first_couple = list(numbers_to_use)
                random.shuffle(first_couple)
                nb_to_use = list(second_couple)
                random.shuffle(nb_to_use)
                all_nb = [nb_to_use.pop(0), first_couple.pop(0)]
                remaining = nb_to_use + first_couple
            random.shuffle(remaining)
            all_nb += remaining

        super().setup("numbers", nb=all_nb, shuffle_nbs=False, **options)

        product = Product(
            [getattr(self, 'nb' + str(i + 1)) for i in range(self.nb_nb)])
        self.product_str = product.printed
        self.result = product.evaluate()
コード例 #4
0
    def __init__(self, build_data, **options):
        super().setup("minimal", **options)
        if self.variant == 'with_a_decimal':
            second_couple = shared.mc_source.next('int_deci_clever_pairs')
        elif self.variant == 'integers_only':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever_in=[4, 5])
        elif self.variant == 'fifths_series':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever=5,
                                                  union={
                                                      'table_name':
                                                      'int_deci_clever_pairs',
                                                      'clever': 5})
        elif self.variant == 'quarters_series':
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever=4,
                                                  union={
                                                      'table_name':
                                                      'int_deci_clever_pairs',
                                                      'clever': 4})
        else:
            second_couple = shared.mc_source.next('intpairs_2to500',
                                                  clever_in=[4, 5, 10],
                                                  union={
                                                      'table_name':
                                                      'int_deci_clever_pairs'})

        # We shuffle the numbers in a special way
        if len(build_data) == 1:
            # There is only one number in addition to the 2 special ones
            # so either we put it in the first place, or in the middle
            # (not at the end, otherwise, the 2 special ones would be at the
            # two first places)
            special_ones = list(second_couple)
            random.shuffle(special_ones)
            all_nb = [list(build_data).pop(0), special_ones.pop(0)]
            random.shuffle(all_nb)
            all_nb += [special_ones.pop(0)]
        else:
            # It is assumed there are 2 build_data (so 4 altogether)
            # In order to avoid having the two "special" numbers in a row at
            # the two first places, we will shuffle all numbers in a special
            # way.
            if random.choice([True, False]):
                # In this case, the first number will NOT be from the "special"
                # ones, so no matter what follows
                nb_to_use = list(build_data)
                random.shuffle(nb_to_use)
                all_nb = [nb_to_use.pop(0)]
                remaining = nb_to_use + list(second_couple)
            else:
                # In this case, it will, so, at the second place we put a
                # number from the other source (the user specified one)
                first_couple = list(build_data)
                random.shuffle(first_couple)
                nb_to_use = list(second_couple)
                random.shuffle(nb_to_use)
                all_nb = [nb_to_use.pop(0), first_couple.pop(0)]
                remaining = nb_to_use + first_couple
            random.shuffle(remaining)
            all_nb += remaining

        super().setup("numbers", nb=all_nb, shuffle_nbs=False, **options)
        self.transduration = 15

        product = Product([getattr(self,
                                   'nb' + str(i + 1))
                           for i in range(self.nb_nb)])
        self.product_str = product.printed
        self.result = product.evaluate()