The above code works but the second code shows typerror: print(a.factorial(a, 5))TypeError: factorial() takes 2 positional arguments but 3 were given:
class Factorial:
def factorial(self, num):
if num == 0:
return 1
if num ==1:
return 1
else:
return num * self.factorial(self, num-1)
def main():
a = Factorial()
print(Factorial.factorial(Factorial, 5))
main()
The second code is as follows:
class Factorial:
def factorial(self, num):
if num == 0:
return 1
if num ==1:
return 1
else:
return num * self.factorial(self, num-1)
def main():
a = Factorial()
print(a.factorial(a, 5))
main()