mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
codespell --quiet-level=2 (#1711)
* codespell --quiet-level=2 Suppress the BINARY FILE warnings * fixup! Format Python code with psf/black push
This commit is contained in:
parent
2cf7e8f994
commit
46ac50a28e
4
.github/workflows/codespell.yml
vendored
4
.github/workflows/codespell.yml
vendored
|
@ -10,5 +10,5 @@ jobs:
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
- run: pip install codespell flake8
|
- run: pip install codespell flake8
|
||||||
- run: |
|
- run: |
|
||||||
SKIP="./.*,./other/dictionary.txt,./other/words,./project_euler/problem_22/p022_names.txt,*.bak,*.gif,*.jpeg,*.jpg,*.json,*.png,*.pyc"
|
SKIP="./.*,./other/dictionary.txt,./other/words,./project_euler/problem_22/p022_names.txt"
|
||||||
codespell -L ans,fo,hist,iff,secant,tim --skip=$SKIP
|
codespell -L ans,fo,hist,iff,secant,tim --skip=$SKIP --quiet-level=2
|
||||||
|
|
|
@ -4,10 +4,13 @@ Approximates the area under the curve using the trapezoidal rule
|
||||||
|
|
||||||
from typing import Callable, Union
|
from typing import Callable, Union
|
||||||
|
|
||||||
def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
|
|
||||||
x_start: Union[int, float],
|
def trapezoidal_area(
|
||||||
x_end: Union[int, float],
|
fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
steps: int = 100) -> float:
|
x_start: Union[int, float],
|
||||||
|
x_end: Union[int, float],
|
||||||
|
steps: int = 100,
|
||||||
|
) -> float:
|
||||||
"""
|
"""
|
||||||
Treats curve as a collection of linear lines and sums the area of the
|
Treats curve as a collection of linear lines and sums the area of the
|
||||||
trapezium shape they form
|
trapezium shape they form
|
||||||
|
@ -34,9 +37,9 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
for i in range(steps):
|
for i in range(steps):
|
||||||
# Approximates small segments of curve as linear and solve
|
# Approximates small segments of curve as linear and solve
|
||||||
# for trapezoidal area
|
# for trapezoidal area
|
||||||
x2 = (x_end - x_start)/steps + x1
|
x2 = (x_end - x_start) / steps + x1
|
||||||
fx2 = fnc(x2)
|
fx2 = fnc(x2)
|
||||||
area += abs(fx2 + fx1) * (x2 - x1)/2
|
area += abs(fx2 + fx1) * (x2 - x1) / 2
|
||||||
# Increment step
|
# Increment step
|
||||||
x1 = x2
|
x1 = x2
|
||||||
fx1 = fx2
|
fx1 = fx2
|
||||||
|
@ -44,12 +47,13 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return x**3 + x**2
|
return x ** 3 + x ** 2
|
||||||
|
|
||||||
print("f(x) = 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:")
|
print("The area between the curve, x = -5, x = 5 and the x axis is:")
|
||||||
i = 10
|
i = 10
|
||||||
while i <= 100000:
|
while i <= 100000:
|
||||||
print(f"with {i} steps: {trapezoidal_area(f, -5, 5, i)}")
|
print(f"with {i} steps: {trapezoidal_area(f, -5, 5, i)}")
|
||||||
i*=10
|
i *= 10
|
||||||
|
|
|
@ -24,7 +24,7 @@ def armstrong_number(n: int) -> bool:
|
||||||
"""
|
"""
|
||||||
if not isinstance(n, int) or n < 1:
|
if not isinstance(n, int) or n < 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Initialization of sum and number of digits.
|
# Initialization of sum and number of digits.
|
||||||
sum = 0
|
sum = 0
|
||||||
number_of_digits = 0
|
number_of_digits = 0
|
||||||
|
@ -37,7 +37,7 @@ def armstrong_number(n: int) -> bool:
|
||||||
temp = n
|
temp = n
|
||||||
while temp > 0:
|
while temp > 0:
|
||||||
rem = temp % 10
|
rem = temp % 10
|
||||||
sum += (rem ** number_of_digits)
|
sum += rem ** number_of_digits
|
||||||
temp //= 10
|
temp //= 10
|
||||||
return n == sum
|
return n == sum
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ def main():
|
||||||
print(f"{num} is {'' if armstrong_number(num) else 'not '}an Armstrong number.")
|
print(f"{num} is {'' if armstrong_number(num) else 'not '}an Armstrong number.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
from typing import Callable, Union
|
from typing import Callable, Union
|
||||||
import math as m
|
import math as m
|
||||||
|
|
||||||
def line_length(fnc: Callable[[Union[int, float]], Union[int, float]],
|
|
||||||
x_start: Union[int, float],
|
def line_length(
|
||||||
x_end: Union[int, float],
|
fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
steps: int = 100) -> float:
|
x_start: Union[int, float],
|
||||||
|
x_end: Union[int, float],
|
||||||
|
steps: int = 100,
|
||||||
|
) -> float:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Approximates the arc length of a line segment by treating the curve as a
|
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]],
|
||||||
|
|
||||||
return length
|
return length
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return m.sin(10*x)
|
return m.sin(10 * x)
|
||||||
|
|
||||||
print("f(x) = sin(10 * x)")
|
print("f(x) = sin(10 * x)")
|
||||||
print("The length of the curve from x = -10 to x = 10 is:")
|
print("The length of the curve from x = -10 to x = 10 is:")
|
||||||
|
|
|
@ -4,10 +4,13 @@ Approximates the area under the curve using the trapezoidal rule
|
||||||
|
|
||||||
from typing import Callable, Union
|
from typing import Callable, Union
|
||||||
|
|
||||||
def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
|
|
||||||
x_start: Union[int, float],
|
def trapezoidal_area(
|
||||||
x_end: Union[int, float],
|
fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
steps: int = 100) -> float:
|
x_start: Union[int, float],
|
||||||
|
x_end: Union[int, float],
|
||||||
|
steps: int = 100,
|
||||||
|
) -> float:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Treats curve as a collection of linear lines and sums the area of the
|
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]],
|
||||||
|
|
||||||
# Approximates small segments of curve as linear and solve
|
# Approximates small segments of curve as linear and solve
|
||||||
# for trapezoidal area
|
# for trapezoidal area
|
||||||
x2 = (x_end - x_start)/steps + x1
|
x2 = (x_end - x_start) / steps + x1
|
||||||
fx2 = fnc(x2)
|
fx2 = fnc(x2)
|
||||||
area += abs(fx2 + fx1) * (x2 - x1)/2
|
area += abs(fx2 + fx1) * (x2 - x1) / 2
|
||||||
|
|
||||||
# Increment step
|
# Increment step
|
||||||
x1 = x2
|
x1 = x2
|
||||||
|
@ -52,7 +55,7 @@ def trapezoidal_area(fnc: Callable[[Union[int, float]], Union[int, float]],
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return x**3
|
return x ** 3
|
||||||
|
|
||||||
print("f(x) = x^3")
|
print("f(x) = x^3")
|
||||||
print("The area between the curve, x = -10, x = 10 and the x axis is:")
|
print("The area between the curve, x = -10, x = 10 and the x axis is:")
|
||||||
|
@ -60,4 +63,4 @@ if __name__ == "__main__":
|
||||||
while i <= 100000:
|
while i <= 100000:
|
||||||
area = trapezoidal_area(f, -5, 5, i)
|
area = trapezoidal_area(f, -5, 5, i)
|
||||||
print("with {} steps: {}".format(i, area))
|
print("with {} steps: {}".format(i, area))
|
||||||
i*=10
|
i *= 10
|
||||||
|
|
Loading…
Reference in New Issue
Block a user