Skip to content

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.

License

Notifications You must be signed in to change notification settings

rkstudio585/Factorial-Calculator-in-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

📊 Factorial Calculator in Python


In C script

In python GUI

Logo


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:
    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! 😄


About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages