From ab36e331e0b2626b66d6352bf51c282f9fc89ca8 Mon Sep 17 00:00:00 2001 From: Himanshu Chaurasia <106426822+Himanshuchaurasia9@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:35:57 +0530 Subject: [PATCH 1/2] Create factorial_using_class.py Factorial Program using class. Github - HimanshuChaurasia9 Date - 23-10-2024 --- Python/factorial_using_class.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Python/factorial_using_class.py diff --git a/Python/factorial_using_class.py b/Python/factorial_using_class.py new file mode 100644 index 00000000..b218fce1 --- /dev/null +++ b/Python/factorial_using_class.py @@ -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}") From e938418b46eaae70faa60e41905e14b8f3b4b6ad Mon Sep 17 00:00:00 2001 From: Himanshu Chaurasia <106426822+Himanshuchaurasia9@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:37:13 +0530 Subject: [PATCH 2/2] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c6c487a0..90ababd9 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -52,4 +52,5 @@ | Ankita Sinha Ray |ankitasray| | Aditya Pandey |Aditya7pandey| | Yash Bandal |Yash Bandal| -| Harshit Jaiswal |Harshit Jaiswal| \ No newline at end of file +| Harshit Jaiswal |Harshit Jaiswal| +| Himanshu Chaurasia |Himanshu Chaurasia|