MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / real_power

Function real_power

electronics/real_and_reactive_power.py:4–22  ·  view source on GitHub ↗

Calculate real power from apparent power and power factor. Examples: >>> real_power(100, 0.9) 90.0 >>> real_power(0, 0.8) 0.0 >>> real_power(100, -0.9) -90.0

(apparent_power: float, power_factor: float)

Source from the content-addressed store, hash-verified

2
3
4def real_power(apparent_power: float, power_factor: float) -> float:
5 """
6 Calculate real power from apparent power and power factor.
7
8 Examples:
9 >>> real_power(100, 0.9)
10 90.0
11 >>> real_power(0, 0.8)
12 0.0
13 >>> real_power(100, -0.9)
14 -90.0
15 """
16 if (
17 not isinstance(power_factor, (int, float))
18 or power_factor < -1
19 or power_factor > 1
20 ):
21 raise ValueError("power_factor must be a valid float value between -1 and 1.")
22 return apparent_power * power_factor
23
24
25def reactive_power(apparent_power: float, power_factor: float) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected