mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
a2236cfb97
* Improved Formatting of basic_maths.py - Added docstrings. - Improved whitespace formatting. - Renamed functions to match snake_case. * Improved Formatting of factorial_python.py - Added docstrings. - Improved whitespace formatting. - Renamed constants to match UPPER_CASE. * Improved Formatting of factorial_recursive.py - Improved whitespace formatting to meet PyLint standards. * Improved Code to Conform to PyLint - Renamed `max` to `max_num` to avoid redefining built-in 'max' [pylint] - Removed unnecessary parens after 'while' keyword [pylint] * Improved Formatting of factorial_recursive.py - Added docstrings. - Improved whitespace formatting.
20 lines
531 B
Python
20 lines
531 B
Python
"""Python program to find the factorial of a number provided by the user."""
|
|
|
|
# change the value for a different result
|
|
NUM = 10
|
|
|
|
# uncomment to take input from the user
|
|
# num = int(input("Enter a number: "))
|
|
|
|
FACTORIAL = 1
|
|
|
|
# check if the number is negative, positive or zero
|
|
if NUM < 0:
|
|
print("Sorry, factorial does not exist for negative numbers")
|
|
elif NUM == 0:
|
|
print("The factorial of 0 is 1")
|
|
else:
|
|
for i in range(1, NUM + 1):
|
|
FACTORIAL = FACTORIAL * i
|
|
print("The factorial of", NUM, "is", FACTORIAL)
|