Homework 6 - on Class

This notebook imports a calculator module built as a class.

First we import the module

In [1]:
import calc as ca

Then, we have to create a object from the class, as the constructor does not need any external parameters, we leave it blank

In [2]:
c=ca.calculator()
In [3]:
dir(c)
Out[3]:
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 'div',
 'mult',
 'pow',
 'sub',
 'sum']

and we use it!

In [4]:
a=2
b=5

Sum

In [5]:
c.sum(a,b)
Out[5]:
7.0

Subtraction

In [6]:
c.sub(a,b)
Out[6]:
-3.0

Multiplication

In [7]:
c.mult(a,b)
Out[7]:
10.0

Division

In [8]:
c.div(a,b)
Out[8]:
0.4

Power

In [9]:
c.pow(a,b)
Out[9]:
32.0