Skip to content

Commit 2c775d9

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 55abd63 commit 2c775d9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

physics/bernoullis_principle.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Title: Bernoulli's Principle Implementation
33
44
Description:
5-
This Python script implements Bernoulli's Principle, which describes the behavior of
5+
This Python script implements Bernoulli's Principle, which describes the behavior of
66
a fluid under varying conditions of pressure, velocity, and height. Bernoulli's equation
7-
is applied to an incompressible, frictionless fluid to calculate the unknown variable
7+
is applied to an incompressible, frictionless fluid to calculate the unknown variable
88
(pressure, velocity, or height) when the others are known.
99
1010
Bernoulli's Equation:
@@ -20,10 +20,11 @@
2020
The function `bernoullis_principle` calculates one unknown variable based on inputs and returns the result.
2121
"""
2222

23+
2324
def bernoullis_principle(P1, v1, h1, P2=None, v2=None, h2=None, density=1000, g=9.81):
2425
"""
2526
Apply Bernoulli's Principle to calculate unknown variables.
26-
27+
2728
Parameters:
2829
P1 : float -> Pressure at point 1 (in Pascals)
2930
v1 : float -> Velocity at point 1 (in m/s)
@@ -33,18 +34,18 @@ def bernoullis_principle(P1, v1, h1, P2=None, v2=None, h2=None, density=1000, g=
3334
h2 : float -> Height at point 2 (in meters) (optional)
3435
density : float -> Fluid density (in kg/m^3) (default is 1000 for water)
3536
g : float -> Acceleration due to gravity (default is 9.81 m/s²)
36-
37+
3738
Returns:
3839
- If one unknown is provided (P2, v2, or h2), the function calculates the missing value.
3940
"""
40-
41+
4142
if P2 is None:
4243
# Calculate Pressure at point 2 (P2)
4344
P2 = P1 + 0.5 * density * (v1**2 - v2**2) + density * g * (h1 - h2)
4445
return P2
4546
elif v2 is None:
4647
# Calculate Velocity at point 2 (v2)
47-
v2 = ((2 * (P1 - P2 + density * g * (h1 - h2))) / density + v1**2)**0.5
48+
v2 = ((2 * (P1 - P2 + density * g * (h1 - h2))) / density + v1**2) ** 0.5
4849
return v2
4950
elif h2 is None:
5051
# Calculate Height at point 2 (h2)
@@ -57,10 +58,10 @@ def bernoullis_principle(P1, v1, h1, P2=None, v2=None, h2=None, density=1000, g=
5758
# Example Usage
5859
# Given: P1 = 101325 Pa, v1 = 5 m/s, h1 = 10 m, v2 = 10 m/s, h2 = 5 m
5960
P1 = 101325 # Pressure at point 1 in Pascals
60-
v1 = 5 # Velocity at point 1 in m/s
61-
h1 = 10 # Height at point 1 in meters
62-
v2 = 10 # Velocity at point 2 in m/s
63-
h2 = 5 # Height at point 2 in meters
61+
v1 = 5 # Velocity at point 1 in m/s
62+
h1 = 10 # Height at point 1 in meters
63+
v2 = 10 # Velocity at point 2 in m/s
64+
h2 = 5 # Height at point 2 in meters
6465

6566
# Calculate pressure at point 2 (P2)
6667
P2 = bernoullis_principle(P1, v1, h1, v2=v2, h2=h2)

0 commit comments

Comments
 (0)