Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / trial / calculus / base_3.py
1 # -*- test-case-name: calculus.test.test_base_3 -*-
2
3 class Calculation(object):
4     def _make_ints(self, *args):
5         try:
6             return map(int, args)
7         except ValueError:
8             raise TypeError("Couldn't coerce arguments to integers: %s" % args)
9
10     def add(self, a, b):
11         a, b = self._make_ints(a, b)
12         return a + b
13     
14     def subtract(self, a, b):
15         a, b = self._make_ints(a, b)
16         return a - b
17
18     def multiply(self, a, b):
19         a, b = self._make_ints(a, b)
20         return a * b
21
22     def divide(self, a, b):
23         a, b = self._make_ints(a, b)
24         return a / b