The black formatter is no longer beta (#5960)

* The black formatter is no longer beta

* pre-commit autoupdate

* pre-commit autoupdate

* Remove project_euler/problem_145 which is killing our CI tests

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2022-01-30 20:29:54 +01:00
committed by GitHub
parent c15a4d5af6
commit 24d3cf8244
81 changed files with 139 additions and 228 deletions

View File

@@ -19,7 +19,7 @@ def surface_area_cube(side_length: float) -> float:
"""
if side_length < 0:
raise ValueError("surface_area_cube() only accepts non-negative values")
return 6 * side_length ** 2
return 6 * side_length**2
def surface_area_sphere(radius: float) -> float:
@@ -39,7 +39,7 @@ def surface_area_sphere(radius: float) -> float:
"""
if radius < 0:
raise ValueError("surface_area_sphere() only accepts non-negative values")
return 4 * pi * radius ** 2
return 4 * pi * radius**2
def surface_area_hemisphere(radius: float) -> float:
@@ -62,7 +62,7 @@ def surface_area_hemisphere(radius: float) -> float:
"""
if radius < 0:
raise ValueError("surface_area_hemisphere() only accepts non-negative values")
return 3 * pi * radius ** 2
return 3 * pi * radius**2
def surface_area_cone(radius: float, height: float) -> float:
@@ -90,7 +90,7 @@ def surface_area_cone(radius: float, height: float) -> float:
"""
if radius < 0 or height < 0:
raise ValueError("surface_area_cone() only accepts non-negative values")
return pi * radius * (radius + (height ** 2 + radius ** 2) ** 0.5)
return pi * radius * (radius + (height**2 + radius**2) ** 0.5)
def surface_area_cylinder(radius: float, height: float) -> float:
@@ -158,7 +158,7 @@ def area_square(side_length: float) -> float:
"""
if side_length < 0:
raise ValueError("area_square() only accepts non-negative values")
return side_length ** 2
return side_length**2
def area_triangle(base: float, height: float) -> float:
@@ -307,7 +307,7 @@ def area_circle(radius: float) -> float:
"""
if radius < 0:
raise ValueError("area_circle() only accepts non-negative values")
return pi * radius ** 2
return pi * radius**2
def area_ellipse(radius_x: float, radius_y: float) -> float:

View File

@@ -50,7 +50,7 @@ def trapezoidal_area(
if __name__ == "__main__":
def f(x):
return x ** 3 + x ** 2
return x**3 + x**2
print("f(x) = x^3 + x^2")
print("The area between the curve, x = -5, x = 5 and the x axis is:")

View File

@@ -36,7 +36,7 @@ def armstrong_number(n: int) -> bool:
temp = n
while temp > 0:
rem = temp % 10
sum += rem ** number_of_digits
sum += rem**number_of_digits
temp //= 10
return n == sum
@@ -63,7 +63,7 @@ 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
sum += cnt * i**digit_total
return n == sum

View File

@@ -81,14 +81,14 @@ def sum_of_divisors(n: int) -> int:
temp += 1
n = int(n / 2)
if temp > 1:
s *= (2 ** temp - 1) / (2 - 1)
s *= (2**temp - 1) / (2 - 1)
for i in range(3, int(math.sqrt(n)) + 1, 2):
temp = 1
while n % i == 0:
temp += 1
n = int(n / i)
if temp > 1:
s *= (i ** temp - 1) / (i - 1)
s *= (i**temp - 1) / (i - 1)
return int(s)

View File

@@ -24,7 +24,7 @@ def binomial_distribution(successes: int, trials: int, prob: float) -> float:
raise ValueError("the function is defined for non-negative integers")
if not 0 < prob < 1:
raise ValueError("prob has to be in range of 1 - 0")
probability = (prob ** successes) * ((1 - prob) ** (trials - successes))
probability = (prob**successes) * ((1 - prob) ** (trials - successes))
# Calculate the binomial coefficient: n! / k!(n-k)!
coefficient = float(factorial(trials))
coefficient /= factorial(successes) * factorial(trials - successes)

View File

@@ -159,7 +159,7 @@ def fib_binet(n: int) -> list[int]:
raise Exception("n is too large")
sqrt_5 = sqrt(5)
phi = (1 + sqrt_5) / 2
return [round(phi ** i / sqrt_5) for i in range(n + 1)]
return [round(phi**i / sqrt_5) for i in range(n + 1)]
if __name__ == "__main__":

View File

@@ -52,7 +52,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
>>> gaussian(2523, mu=234234, sigma=3425)
0.0
"""
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / (2 * sigma ** 2))
return 1 / sqrt(2 * pi * sigma**2) * exp(-((x - mu) ** 2) / (2 * sigma**2))
if __name__ == "__main__":

View File

@@ -14,8 +14,8 @@ def karatsuba(a, b):
m1 = max(len(str(a)), len(str(b)))
m2 = m1 // 2
a1, a2 = divmod(a, 10 ** m2)
b1, b2 = divmod(b, 10 ** m2)
a1, a2 = divmod(a, 10**m2)
b1, b2 = divmod(b, 10**m2)
x = karatsuba(a2, b2)
y = karatsuba((a1 + a2), (b1 + b2))

View File

@@ -20,7 +20,7 @@ def pi_estimator(iterations: int):
"""
# A local function to see if a dot lands in the circle.
def is_in_circle(x: float, y: float) -> bool:
distance_from_centre = sqrt((x ** 2) + (y ** 2))
distance_from_centre = sqrt((x**2) + (y**2))
# Our circle has a radius of 1, so a distance
# greater than 1 would land outside the circle.
return distance_from_centre <= 1

View File

@@ -56,7 +56,7 @@ def trapezoidal_area(
if __name__ == "__main__":
def f(x):
return x ** 3
return x**3
print("f(x) = x^3")
print("The area between the curve, x = -10, x = 10 and the x axis is:")

View File

@@ -58,9 +58,9 @@ def perfect_square_binary_search(n: int) -> bool:
right = n
while left <= right:
mid = (left + right) // 2
if mid ** 2 == n:
if mid**2 == n:
return True
elif mid ** 2 > n:
elif mid**2 > n:
right = mid - 1
else:
left = mid + 1

View File

@@ -11,7 +11,7 @@ class Point:
True, if the point lies in the unit circle
False, otherwise
"""
return (self.x ** 2 + self.y ** 2) <= 1
return (self.x**2 + self.y**2) <= 1
@classmethod
def random_unit_square(cls):

View File

@@ -12,7 +12,7 @@ def evaluate_poly(poly: Sequence[float], x: float) -> float:
>>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10.0)
79800.0
"""
return sum(c * (x ** i) for i, c in enumerate(poly))
return sum(c * (x**i) for i, c in enumerate(poly))
def horner(poly: Sequence[float], x: float) -> float:

View File

@@ -91,7 +91,7 @@ class FFT:
next_ncol = self.C_max_length // 2
while next_ncol > 0:
new_dft = [[] for i in range(next_ncol)]
root = self.root ** next_ncol
root = self.root**next_ncol
# First half of next step
current_root = 1

View File

@@ -48,4 +48,4 @@ def sieve(n):
return prime
print(sieve(10 ** 6))
print(sieve(10**6))

View File

@@ -25,4 +25,4 @@ def sum_of_geometric_progression(
return num_of_terms * first_term
# Formula for finding sum of n terms of a GeometricProgression
return (first_term / (1 - common_ratio)) * (1 - common_ratio ** num_of_terms)
return (first_term / (1 - common_ratio)) * (1 - common_ratio**num_of_terms)