Skip to content

Commit 2d029ac

Browse files
committed
create readme.md file for that problems
1 parent 3e12508 commit 2d029ac

File tree

1 file changed

+93
-1
lines changed
  • Interview/Python/Solutions/140+ Basic Python Programs/Program 16

1 file changed

+93
-1
lines changed
Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
1-
# Program16
1+
# ✨ Factorial Calculator (Python)
2+
3+
This Python program calculates the **factorial** of a given non-negative integer using a `for` loop.
4+
5+
---
6+
7+
## πŸ“Œ Problem Statement
8+
9+
**Write a Python program to find the factorial of a number.**
10+
11+
---
12+
13+
## ℹ️ What is a Factorial?
14+
15+
The **factorial** of a number `n` (written as `n!`) is the product of all positive integers from `1` to `n`.
16+
17+
### βœ… Examples:
18+
19+
- `5! = 5 Γ— 4 Γ— 3 Γ— 2 Γ— 1 = 120`
20+
- `0! = 1` (by definition)
21+
22+
---
23+
24+
## βœ… Sample Code
25+
26+
```python
27+
# Python program to find the factorial of a number
28+
29+
# Input from user
30+
num = int(input("Enter a non-negative integer: "))
31+
32+
# Factorial calculation
33+
if num < 0:
34+
print("Factorial is not defined for negative numbers.")
35+
else:
36+
factorial = 1
37+
for i in range(1, num + 1):
38+
factorial *= i
39+
print(f"The factorial of {num} is {factorial}")
40+
```
41+
42+
---
43+
44+
## ▢️ Example Runs
45+
46+
```bash
47+
Enter a non-negative integer: 5
48+
The factorial of 5 is 120
49+
```
50+
51+
```bash
52+
Enter a non-negative integer: 0
53+
The factorial of 0 is 1
54+
```
55+
56+
```bash
57+
Enter a non-negative integer: -3
58+
Factorial is not defined for negative numbers.
59+
```
60+
61+
---
62+
63+
## πŸš€ How to Run
64+
65+
1. Save the code in a file named `factorial.py`
66+
2. Run the script using:
67+
68+
```bash
69+
python factorial.py
70+
```
71+
72+
---
73+
74+
## πŸ“ Suggested Project Structure
75+
76+
```
77+
factorial/
78+
β”œβ”€β”€ factorial.py
79+
└── README.md
80+
```
81+
82+
---
83+
84+
## πŸ’‘ You Can Try
85+
86+
- Implement the factorial using **recursion**.
87+
- Use the built-in `math.factorial()` function for comparison.
88+
- Plot the growth of factorial values using `matplotlib`.
89+
90+
---
91+
92+
Happy Coding! πŸ”’πŸŽ―
93+

0 commit comments

Comments
Β (0)