How to compute power from current and voltage in Python using UliEngineering

You can easily compute electrical power from current and voltage using the UliEngineering Python library:

power_by_current_and_voltage.py
from UliEngineering.Electronics.Power import *
from UliEngineering.EngineerIO import *

# Compute power for 5V at 1A
power = power_by_current_and_voltage("5V", "1A")
print(f"Power for 5V at 1A: {format_value(power, 'W')}")

# Compute power for 12V at 0.5A
power = power_by_current_and_voltage("12V", "0.5A")
print(f"Power for 12V at 0.5A: {format_value(power, 'W')}")

Example output

power_by_current_and_voltage_output.txt
Power for 5V at 1A: 5.00 W
Power for 12V at 0.5A: 6.00 W

The power is computed using the formula: $P = V \times I$


Check out similar posts by category: Electronics, Python