Add flake8-builtins to pre-commit and fix errors (#7105)

Ignore `A003`

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
Caeden
2022-10-13 15:23:59 +01:00
committed by GitHub
parent e661b98829
commit d5a9f649b8
31 changed files with 113 additions and 106 deletions

View File

@ -25,7 +25,7 @@ def armstrong_number(n: int) -> bool:
return False
# Initialization of sum and number of digits.
sum = 0
total = 0
number_of_digits = 0
temp = n
# Calculation of digits of the number
@ -36,9 +36,9 @@ def armstrong_number(n: int) -> bool:
temp = n
while temp > 0:
rem = temp % 10
sum += rem**number_of_digits
total += rem**number_of_digits
temp //= 10
return n == sum
return n == total
def pluperfect_number(n: int) -> bool:
@ -55,7 +55,7 @@ def pluperfect_number(n: int) -> bool:
# Init a "histogram" of the digits
digit_histogram = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
digit_total = 0
sum = 0
total = 0
temp = n
while temp > 0:
temp, rem = divmod(temp, 10)
@ -63,9 +63,9 @@ def pluperfect_number(n: int) -> bool:
digit_total += 1
for (cnt, i) in zip(digit_histogram, range(len(digit_histogram))):
sum += cnt * i**digit_total
total += cnt * i**digit_total
return n == sum
return n == total
def narcissistic_number(n: int) -> bool:

View File

@ -67,7 +67,7 @@ def _subsum(
@param precision: same as precision in main function
@return: floating-point number whose integer part is not important
"""
sum = 0.0
total = 0.0
for sum_index in range(digit_pos_to_extract + precision):
denominator = 8 * sum_index + denominator_addend
if sum_index < digit_pos_to_extract:
@ -79,8 +79,8 @@ def _subsum(
)
else:
exponential_term = pow(16, digit_pos_to_extract - 1 - sum_index)
sum += exponential_term / denominator
return sum
total += exponential_term / denominator
return total
if __name__ == "__main__":

View File

@ -14,13 +14,13 @@ def negative_exist(arr: list) -> int:
[-2, 0, 0, 0, 0]
"""
arr = arr or [0]
max = arr[0]
max_number = arr[0]
for i in arr:
if i >= 0:
return 0
elif max <= i:
max = i
return max
elif max_number <= i:
max_number = i
return max_number
def kadanes(arr: list) -> int:

View File

@ -2,7 +2,7 @@ import math
from collections.abc import Generator
def slow_primes(max: int) -> Generator[int, None, None]:
def slow_primes(max_n: int) -> Generator[int, None, None]:
"""
Return a list of all primes numbers up to max.
>>> list(slow_primes(0))
@ -20,7 +20,7 @@ def slow_primes(max: int) -> Generator[int, None, None]:
>>> list(slow_primes(10000))[-1]
9973
"""
numbers: Generator = (i for i in range(1, (max + 1)))
numbers: Generator = (i for i in range(1, (max_n + 1)))
for i in (n for n in numbers if n > 1):
for j in range(2, i):
if (i % j) == 0:
@ -29,7 +29,7 @@ def slow_primes(max: int) -> Generator[int, None, None]:
yield i
def primes(max: int) -> Generator[int, None, None]:
def primes(max_n: int) -> Generator[int, None, None]:
"""
Return a list of all primes numbers up to max.
>>> list(primes(0))
@ -47,7 +47,7 @@ def primes(max: int) -> Generator[int, None, None]:
>>> list(primes(10000))[-1]
9973
"""
numbers: Generator = (i for i in range(1, (max + 1)))
numbers: Generator = (i for i in range(1, (max_n + 1)))
for i in (n for n in numbers if n > 1):
# only need to check for factors up to sqrt(i)
bound = int(math.sqrt(i)) + 1
@ -58,7 +58,7 @@ def primes(max: int) -> Generator[int, None, None]:
yield i
def fast_primes(max: int) -> Generator[int, None, None]:
def fast_primes(max_n: int) -> Generator[int, None, None]:
"""
Return a list of all primes numbers up to max.
>>> list(fast_primes(0))
@ -76,9 +76,9 @@ def fast_primes(max: int) -> Generator[int, None, None]:
>>> list(fast_primes(10000))[-1]
9973
"""
numbers: Generator = (i for i in range(1, (max + 1), 2))
numbers: Generator = (i for i in range(1, (max_n + 1), 2))
# It's useless to test even numbers as they will not be prime
if max > 2:
if max_n > 2:
yield 2 # Because 2 will not be tested, it's necessary to yield it now
for i in (n for n in numbers if n > 1):
bound = int(math.sqrt(i)) + 1

View File

@ -8,9 +8,9 @@ def sum_of_series(first_term: int, common_diff: int, num_of_terms: int) -> float
>>> sum_of_series(1, 10, 100)
49600.0
"""
sum = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
total = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
# formula for sum of series
return sum
return total
def main():