Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a program of factorial using class in python. #418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
| Ankita Sinha Ray |<a href="https://github.com/ankitasray">ankitasray</a>|
| Aditya Pandey |<a href="https://github.com/Aditya7pandey">Aditya7pandey</a>|
| Yash Bandal |<a href="https://github.com/Yash-Bandal">Yash Bandal</a>|
| Harshit Jaiswal |<a href="https://github.com/harshu84190">Harshit Jaiswal</a>|
| Harshit Jaiswal |<a href="https://github.com/harshu84190">Harshit Jaiswal</a>|
| Himanshu Chaurasia |<a href="https://github.com/Himanshuchaurasia9">Himanshu Chaurasia</a>|
21 changes: 21 additions & 0 deletions Python/factorial_using_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class FactorialCalculator:
def __init__(self, number):
self.number = number

def calculate_factorial(self):
if self.number < 0:
return "Factorial is not defined for negative numbers."
elif self.number == 0 or self.number == 1:
return 1
else:
result = 1
for i in range(2, self.number + 1):
result *= i
return result

# Example usage:
if __name__ == "__main__":
num = 6
factorial_calculator = FactorialCalculator(num)
result = factorial_calculator.calculate_factorial()
print(f"The factorial of {num} is: {result}")