Skip to content

Commit 606c871

Browse files
Update find-factorial.md
Use Python's built-in factorial function
1 parent f1f3b6a commit 606c871

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

snippets/python/math-and-numbers/find-factorial.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ title: Find Factorial
33
description: Calculates the factorial of a number.
44
author: dostonnabotov
55
tags: python,math,factorial,utility
6+
contributors: starryknight64
67
---
78

89
```py
10+
import math
11+
912
def factorial(n):
10-
if n == 0:
11-
return 1
12-
return n * factorial(n - 1)
13+
return math.factorial(n)
1314

1415
# Usage:
1516
print(factorial(5)) # Output: 120

0 commit comments

Comments
 (0)