def click_convert(self):
        first_fraction = Fraction.from_string(self.first_fraction)
        second_fraction = Fraction.from_string(self.second_fraction)

        if self.operation == '+':
            self.message_text = str(first_fraction + second_fraction)
        elif self.operation == '-':
            self.message_text = str(first_fraction - second_fraction)
        elif self.operation == '*':
            self.message_text = str(first_fraction * second_fraction)
        elif self.operation == '/':
            try:
                result = str(first_fraction / second_fraction)
            except InvalidFractionError:
                result = 'Error! Cannot divide by zero!'
            self.message_text = str(result)
        else:
            self.message_text = str(list(first_fraction.to_continuous()))
Exemplo n.º 2
0
    def click_convert(self):
        self.logger.log('Button clicked')
        self.logger.log('Selected operation is %s' % self.operation)
        first_fraction = Fraction.from_string(self.first_fraction)
        second_fraction = Fraction.from_string(self.second_fraction)

        if self.operation == '+':
            self.message_text = str(first_fraction + second_fraction)
        elif self.operation == '-':
            self.message_text = str(first_fraction - second_fraction)
        elif self.operation == '*':
            self.message_text = str(first_fraction * second_fraction)
        elif self.operation == '/':
            try:
                result = str(first_fraction / second_fraction)
            except InvalidFractionError:
                result = 'Error! Cannot divide by zero!'
            self.message_text = str(result)
        else:
            self.message_text = str(list(first_fraction.to_continuous()))

        self.logger.log('Result: %s' % self.message_text)
 def test_can_create_1_fraction_from_str(self):
     frac = Fraction.from_string('1')
     self.assertTrue(frac.is_equal(1, 1))
 def test_can_create_minus_1_2_fraction_from_str(self):
     frac = Fraction.from_string('-1/2')
     self.assertTrue(frac.is_equal(-1, 2))