Improve Formatting and Code Quality (#934) · davgit/Python@a2236cf · GitHub
Skip to content

Commit a2236cf

Browse files
PatOnTheBackAnupKumarPanwar
authored andcommitted
Improve Formatting and Code Quality (TheAlgorithms#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.
1 parent bd40179 commit a2236cf

5 files changed

Lines changed: 71 additions & 57 deletions

File tree

maths/basic_maths.py

Lines changed: 38 additions & 28 deletions

maths/factorial_python.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Python program to find the factorial of a number provided by the user.
1+
"""Python program to find the factorial of a number provided by the user."""
22

33
# change the value for a different result
4-
num = 10
4+
NUM = 10
55

66
# uncomment to take input from the user
7-
#num = int(input("Enter a number: "))
7+
# num = int(input("Enter a number: "))
88

9-
factorial = 1
9+
FACTORIAL = 1
1010

1111
# check if the number is negative, positive or zero
12-
if num < 0:
13-
print("Sorry, factorial does not exist for negative numbers")
14-
elif num == 0:
15-
print("The factorial of 0 is 1")
12+
if NUM < 0:
13+
print("Sorry, factorial does not exist for negative numbers")
14+
elif NUM == 0:
15+
print("The factorial of 0 is 1")
1616
else:
17-
for i in range(1,num + 1):
18-
factorial = factorial*i
19-
print("The factorial of",num,"is",factorial)
17+
for i in range(1, NUM + 1):
18+
FACTORIAL = FACTORIAL * i
19+
print("The factorial of", NUM, "is", FACTORIAL)

maths/factorial_recursive.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
def fact(n):
2-
"""
3-
Return 1, if n is 1 or below,
4-
otherwise, return n * fact(n-1).
5-
"""
6-
return 1 if n <= 1 else n * fact(n-1)
2+
"""
3+
Return 1, if n is 1 or below,
4+
otherwise, return n * fact(n-1).
5+
"""
6+
return 1 if n <= 1 else n * fact(n - 1)
7+
78

89
"""
9-
Shown factorial for i,
10+
Show factorial for i,
1011
where i ranges from 1 to 20.
1112
"""
12-
for i in range(1,21):
13-
print(i, ": ", fact(i), sep='')
13+
for i in range(1, 21):
14+
print(i, ": ", fact(i), sep='')

maths/find_lcm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
def find_lcm(num_1, num_2):
77
"""Find the LCM of two numbers."""
8-
max = num_1 if num_1 > num_2 else num_2
9-
lcm = max
10-
while (True):
8+
max_num = num_1 if num_1 > num_2 else num_2
9+
lcm = max_num
10+
while True:
1111
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
1212
break
13-
lcm += max
13+
lcm += max_num
1414
return lcm
1515

1616

sorts/pancake_sort.py

Lines changed: 9 additions & 6 deletions

0 commit comments

Comments
 (0)