I know its dumb question but i am trying to grasp the concepts of OOP in Python. Suppose i want to write the program for factorial in Procedural form, i would do something like this
def factorial(n):
num = 1
while n >= 1:
num = num * n
n = n - 1
return num
f = factorial(3)
print f # 6
Now i want to rewrite the same factorial program in OO way. i am not getting how to write this same function using objects and classes.
class Factorial():
def fact(n):
num = 1
while n >= 1:
num = num * n
n = n - 1
return num
f = Factorial()
a = f.fact(3)
print a # TypeError: fact() takes exactly 1 argument (2 given)
I know this can be done more precisely in Functional way by using lambdas and other things, but i am learning the concepts of OOP. What i am doing wrong ?