Skip to content

Commit e6d2907

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent 5c3aead commit e6d2907

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

maths/area_under_curve.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
from typing import Callable, Union
66

7-
def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
8-
x_start: Union[int, float],
9-
x_end: Union[int, float],
10-
steps: int = 100) -> float:
7+
8+
def trapezoidal_area(
9+
fnc: Callable[[Union[int, float]], Union[int, float]],
10+
x_start: Union[int, float],
11+
x_end: Union[int, float],
12+
steps: int = 100,
13+
) -> float:
1114
"""
1215
Treats curve as a collection of linear lines and sums the area of the
1316
trapezium shape they form
@@ -34,22 +37,23 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
3437
for i in range(steps):
3538
# Approximates small segments of curve as linear and solve
3639
# for trapezoidal area
37-
x2 = (x_end - x_start)/steps + x1
40+
x2 = (x_end - x_start) / steps + x1
3841
fx2 = fnc(x2)
39-
area += abs(fx2 + fx1) * (x2 - x1)/2
42+
area += abs(fx2 + fx1) * (x2 - x1) / 2
4043
# Increment step
4144
x1 = x2
4245
fx1 = fx2
4346
return area
4447

4548

4649
if __name__ == "__main__":
50+
4751
def f(x):
48-
return x**3 + x**2
52+
return x ** 3 + x ** 2
4953

5054
print("f(x) = x^3 + x^2")
5155
print("The area between the curve, x = -5, x = 5 and the x axis is:")
5256
i = 10
5357
while i <= 100000:
5458
print(f"with {i} steps: {trapezoidal_area(f, -5, 5, i)}")
55-
i*=10
59+
i *= 10

maths/armstrong_numbers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def armstrong_number(n: int) -> bool:
2424
"""
2525
if not isinstance(n, int) or n < 1:
2626
return False
27-
27+
2828
# Initialization of sum and number of digits.
2929
sum = 0
3030
number_of_digits = 0
@@ -37,7 +37,7 @@ def armstrong_number(n: int) -> bool:
3737
temp = n
3838
while temp > 0:
3939
rem = temp % 10
40-
sum += (rem ** number_of_digits)
40+
sum += rem ** number_of_digits
4141
temp //= 10
4242
return n == sum
4343

@@ -50,7 +50,7 @@ def main():
5050
print(f"{num} is {'' if armstrong_number(num) else 'not '}an Armstrong number.")
5151

5252

53-
if __name__ == '__main__':
53+
if __name__ == "__main__":
5454
import doctest
5555

5656
doctest.testmod()

maths/line_length.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from typing import Callable, Union
22
import math as m
33

4-
def line_length(fnc: Callable[[Union[int, float]], Union[int, float]],
5-
x_start: Union[int, float],
6-
x_end: Union[int, float],
7-
steps: int = 100) -> float:
4+
5+
def line_length(
6+
fnc: Callable[[Union[int, float]], Union[int, float]],
7+
x_start: Union[int, float],
8+
x_end: Union[int, float],
9+
steps: int = 100,
10+
) -> float:
811

912
"""
1013
Approximates the arc length of a line segment by treating the curve as a
@@ -48,10 +51,11 @@ def line_length(fnc: Callable[[Union[int, float]], Union[int, float]],
4851

4952
return length
5053

54+
5155
if __name__ == "__main__":
5256

5357
def f(x):
54-
return m.sin(10*x)
58+
return m.sin(10 * x)
5559

5660
print("f(x) = sin(10 * x)")
5761
print("The length of the curve from x = -10 to x = 10 is:")

maths/numerical_integration.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
from typing import Callable, Union
66

7-
def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
8-
x_start: Union[int, float],
9-
x_end: Union[int, float],
10-
steps: int = 100) -> float:
7+
8+
def trapezoidal_area(
9+
fnc: Callable[[Union[int, float]], Union[int, float]],
10+
x_start: Union[int, float],
11+
x_end: Union[int, float],
12+
steps: int = 100,
13+
) -> float:
1114

1215
"""
1316
Treats curve as a collection of linear lines and sums the area of the
@@ -39,9 +42,9 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
3942

4043
# Approximates small segments of curve as linear and solve
4144
# for trapezoidal area
42-
x2 = (x_end - x_start)/steps + x1
45+
x2 = (x_end - x_start) / steps + x1
4346
fx2 = fnc(x2)
44-
area += abs(fx2 + fx1) * (x2 - x1)/2
47+
area += abs(fx2 + fx1) * (x2 - x1) / 2
4548

4649
# Increment step
4750
x1 = x2
@@ -52,12 +55,12 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
5255
if __name__ == "__main__":
5356

5457
def f(x):
55-
return x**3
58+
return x ** 3
5659

5760
print("f(x) = x^3")
5861
print("The area between the curve, x = -10, x = 10 and the x axis is:")
5962
i = 10
6063
while i <= 100000:
6164
area = trapezoidal_area(f, -5, 5, i)
6265
print("with {} steps: {}".format(i, area))
63-
i*=10
66+
i *= 10

0 commit comments

Comments
 (0)