I am trying to learn oops in python and I've created a class object. I am trying to import the module and use the methods that I've defined in it. I am learning from the book, Practical Programming. I've tried various things but no success. Any help shall be appreciated. Thanks in advance.
This is my code:
class mynum:
def __init__(self, num, limit):
self.num = num
self.limit = limit
def numf(self):
num = int(input("enter a number"))
limit = int(input('enter the limit'))
total = 0
while (num < limit):
num = num + 9
if num >= limit:
break
else:
total = total + num
print(num)
print("total=",total)
And the last, error I got while trying:
Python 3.4.0 (default, Apr 11 2014, 13:05:18)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import eight
>>>
>>> numb = eight.mynum()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() missing 2 required positional arguments: 'num' and 'limit'
>>> numb = eight.mynum(3,40)
>>> numb
<eight.mynum object at 0xb710412c>
>>>