Recursive Method 06
Recursive method is a dynamic approach, used for Optimal code Big-(O) notation.
This may takes few extra lines of code, yet the resources are less consumed.
Sample Code-01:
class Factorial:
def factorial_number(inumber):
def inner_counter(count, holder):
if count <= 1:
return holder
else:
return inner_counter((count -1),(count * holder))
return inner_counter(inumber, 1)
if __name__ == "__main__":
fact = Factorial.factorial_number(5)
#----------String format( )------------#
print("Factorial for 5 is {fact}".format(fact=fact))
O/P
Factorial for 5 is 120
Comments
Post a Comment