Skip to content

Commit

Permalink
update factorial for python3 (hacktoberfest17#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
hovinh authored and t2013anurag committed Oct 16, 2017
1 parent 2e6b047 commit e6a2adc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions factorial/Factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''THIS VERSION IS FOR PYTHON3'''
result = [i for i in range(1000)]

def fact_dp(n):
result[0] = 1
end = min(n, 1000) + 1
for i in range(1, end):
result[i] = i * result[i - 1]

return result[n]

if __name__ == '__main__':

n = None

try:
n = int(input("Enter a number :"))
except ValueError:
print ("Not a number")

if (n <= 0):
print (1)
else:
print ("Factorial : ", fact_dp(n))

0 comments on commit e6a2adc

Please sign in to comment.