Improve Formatting and Code Quality (#934)

* 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.
This commit is contained in:
PatOnTheBack
2019-07-02 00:05:43 -04:00
committed by Anup Kumar Panwar
parent bd4017928e
commit a2236cfb97
5 changed files with 71 additions and 57 deletions

View File

@ -1,19 +1,19 @@
# Python program to find the factorial of a number provided by the user.
"""Python program to find the factorial of a number provided by the user."""
# change the value for a different result
num = 10
NUM = 10
# uncomment to take input from the user
#num = int(input("Enter a number: "))
# num = int(input("Enter a number: "))
factorial = 1
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")
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)
for i in range(1, NUM + 1):
FACTORIAL = FACTORIAL * i
print("The factorial of", NUM, "is", FACTORIAL)