psf/black code formatting (#1277)

This commit is contained in:
William Zhang
2019-10-05 01:14:13 -04:00
committed by Christian Clauss
parent 07f04a2e55
commit 9eac17a408
291 changed files with 6014 additions and 4571 deletions

View File

@ -1,6 +1,8 @@
#Factorial of a number using memoization
result=[-1]*10
result[0]=result[1]=1
# Factorial of a number using memoization
result = [-1] * 10
result[0] = result[1] = 1
def factorial(num):
"""
>>> factorial(7)
@ -10,19 +12,20 @@ def factorial(num):
>>> [factorial(i) for i in range(5)]
[1, 1, 2, 6, 24]
"""
if num<0:
if num < 0:
return "Number should not be negative."
if result[num]!=-1:
if result[num] != -1:
return result[num]
else:
result[num]=num*factorial(num-1)
#uncomment the following to see how recalculations are avoided
#print(result)
result[num] = num * factorial(num - 1)
# uncomment the following to see how recalculations are avoided
# print(result)
return result[num]
#factorial of num
#uncomment the following to see how recalculations are avoided
# factorial of num
# uncomment the following to see how recalculations are avoided
##result=[-1]*10
##result[0]=result[1]=1
##print(factorial(5))
@ -31,4 +34,5 @@ def factorial(num):
if __name__ == "__main__":
import doctest
doctest.testmod()