Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Calculate Compound Interest
description: Calculates compound interest for a given principal amount, rate, and time period.
author: axorax
tags: python,math,compound interest,finance
tags: math,compound interest,finance
---

```py
Expand Down
17 changes: 17 additions & 0 deletions snippets/python/math-and-numbers/calculate-factorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Calculate Factiorial of a number
description: Calculates factorial of a given number using recursive function
author: SamratBarai
tags: math,factorial,recursive-function
---

```py
def factorial(n):
if n < 0: return "Exception: Cannot calculate factorial for negative numbers" # Handling negative number
elif n == 0 or n == 1: return 1 # Returns 1 if n is 0 or 1
else: return n * factorial(n-1) # Recall the factorial function
```

# Usage:
print(factorial(4)) # Returns 24
print(factorial(-3)) # Returns Exception