Skip to content

Commit 080b658

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1cd5494 commit 080b658

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

searches/bernoullis_principle.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Title: Bernoulli's Principle
33
44
Description:
5-
This algorithm implements Bernoulli's Principle to calculate the unknown pressure
6-
at a second point in a fluid system using the Bernoulli equation. Bernoulli's equation
7-
states that for an incompressible, frictionless fluid, the total mechanical energy
5+
This algorithm implements Bernoulli's Principle to calculate the unknown pressure
6+
at a second point in a fluid system using the Bernoulli equation. Bernoulli's equation
7+
states that for an incompressible, frictionless fluid, the total mechanical energy
88
(remains constant) as the fluid flows.
99
1010
The equation used:
@@ -24,8 +24,15 @@
2424
100732.64
2525
"""
2626

27-
def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
28-
velocity2: float, height2: float, density: float = 1.225) -> float:
27+
28+
def bernoullis_principle(
29+
velocity1: float,
30+
pressure1: float,
31+
height1: float,
32+
velocity2: float,
33+
height2: float,
34+
density: float = 1.225,
35+
) -> float:
2936
"""
3037
Calculate the unknown pressure at a second point in a fluid system using Bernoulli's equation.
3138
@@ -39,7 +46,7 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
3946
4047
Returns:
4148
float: Pressure at point 2 in Pascals
42-
49+
4350
Example:
4451
>>> bernoullis_principle(density=1000, velocity=5, height=10, pressure=101325)
4552
144413.5
@@ -51,8 +58,13 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
5158
g = 9.81 # gravitational constant in m/s^2
5259

5360
# Bernoulli's equation to solve for pressure at point 2
54-
pressure2 = (pressure1 + 0.5 * density * (velocity1 ** 2) + density * g * height1
55-
- 0.5 * density * (velocity2 ** 2) - density * g * height2)
61+
pressure2 = (
62+
pressure1
63+
+ 0.5 * density * (velocity1**2)
64+
+ density * g * height1
65+
- 0.5 * density * (velocity2**2)
66+
- density * g * height2
67+
)
5668

5769
return round(pressure2, 2)
5870

@@ -61,6 +73,7 @@ def bernoullis_principle(velocity1: float, pressure1: float, height1: float,
6173
if __name__ == "__main__":
6274
# Example doctest
6375
import doctest
76+
6477
doctest.testmod()
6578

6679
# Manual test

0 commit comments

Comments
 (0)