Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rkstudio585/factorial-calculator-in-python
The Factorial Calculator is a Python program that computes the factorial of any non-negative integer using recursion. It provides clear, formatted results and handles invalid inputs like negative numbers. Simple to use, it helps users understand factorials and recursion concepts in Python.
https://github.com/rkstudio585/factorial-calculator-in-python
calculator factorial factorial-calculator-in-python n program python rk rk-studio
Last synced: 5 days ago
JSON representation
The Factorial Calculator is a Python program that computes the factorial of any non-negative integer using recursion. It provides clear, formatted results and handles invalid inputs like negative numbers. Simple to use, it helps users understand factorials and recursion concepts in Python.
- Host: GitHub
- URL: https://github.com/rkstudio585/factorial-calculator-in-python
- Owner: rkstudio585
- License: mit
- Created: 2024-09-06T03:39:16.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-06T04:01:44.000Z (4 months ago)
- Last Synced: 2024-11-07T16:16:24.667Z (about 2 months ago)
- Topics: calculator, factorial, factorial-calculator-in-python, n, program, python, rk, rk-studio
- Language: Python
- Homepage: https://github.com/mdriyadkhan585
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π Factorial Calculator in Python
---
[In C script](https://github.com/mdriyadkhan585/Factorial-Calculator-in-C)[In python GUI](https://github.com/mdriyadkhan585/Factorial-Calculator-GUI)
![Logo](logo.svg)
---
Welcome to the **Factorial Calculator** project! This Python program computes the factorial of any non-negative integer using recursion. It's a straightforward tool designed to help you understand factorials and recursion in Python.---
## β¨ Features
- Calculates the factorial of a non-negative integer.
- Handles invalid inputs such as negative numbers.
- Provides clear and well-formatted output.
- Written in Python for simplicity and ease of use.## π‘ What is a Factorial?
The factorial of a non-negative integer `n` is the product of all positive integers less than or equal to `n`. It is denoted as `n!`. For example:
- `5! = 5 Γ 4 Γ 3 Γ 2 Γ 1 = 120`
- Special cases: `0! = 1` and `1! = 1`.## π Program Overview
The program asks the user to input a number and then calculates and displays the factorial of that number using a recursive function.### π Flow of the Program
1. **Welcome Message**: Displays a friendly header.
2. **User Input**: Prompts the user to enter a number.
3. **Validation**: Checks if the number is non-negative.
4. **Calculation & Output**: Computes the factorial and displays it, or shows an error for invalid input.## π How to Run the Program
### 1. **Requirements**
- Python 3.x installed on your system.### 2. **Steps to Run**:
1. **Download or Copy the Code**: Save the Python code into a file named `factorial_calculator.py`.
2. **Open Terminal/Command Prompt**: Navigate to the directory where the file is saved.
3. **Run the Program**: Execute the program using the following command:
```bash
git clone https://github.com/mdriyadkhan585/Factorial-Calculator-in-Python.git
cd Factorial-Calculator-in-Python
python factorial_calculator.py
```### 3. **Example Input and Output**:
#### Example 1: Valid Input
```
=======================================
FACTORIAL CALCULATOR
=======================================
Enter a number: 5---------------------------------------
Factorial of 5 is: 120
---------------------------------------
Thank you for using
the Factorial Calculator!
=======================================
```#### Example 2: Invalid Input (Negative Number)
```
=======================================
FACTORIAL CALCULATOR
=======================================
Enter a number: -5---------------------------------------
Error: Factorial of a negative number doesn't exist.
---------------------------------------
Thank you for using
the Factorial Calculator!
=======================================
```## π§βπ» How to Use the Program
1. **Run the Program**: Follow the instructions to execute the script.
2. **Input a Number**: Enter the number for which you want to calculate the factorial.
3. **View the Result**: The program will display the factorial or an error message if the input is invalid.
4. **Repeat**: You can run the program again to calculate the factorial of a different number.## π File Structure
- `factorial_calculator.py`: Contains the main Python code for calculating factorials.## βοΈ Function Breakdown
- **`def factorial(n):`**: Recursive function to compute the factorial of `n`.
- **`def main():`**: Manages user input and output, formats results, and handles errors.## π Thank You for Using the Factorial Calculator!
We hope this tool helps you understand factorials and recursion. Feel free to modify or extend the program. If you encounter any issues or have suggestions, donβt hesitate to reach out. Happy coding! π---