Part of the series

Several example codes

~1 min read • Updated Sep 29, 2025

Program Overview

This Python program receives two numeric inputs from the user:
1. The resistance of an electrical circuit (in ohms)
2. The current flowing through the circuit (in amperes)
It then calculates the voltage using Ohm’s Law:
Voltage = Current × Resistance


Python Code:


# Get resistance and current from user
resistance = float(input("Enter resistance (ohms): "))
current = float(input("Enter current (amperes): "))

# Calculate voltage
voltage = resistance * current

# Display result
print("\n--- Result ---")
print(f"Voltage of the circuit is: {voltage:.2f} volts")

Sample Output:


Enter resistance (ohms): 10  
Enter current (amperes): 2.5  

--- Result ---  
Voltage of the circuit is: 25.00 volts

Explanation:

- Resistance and current are received using input() and converted to float values
- Voltage is calculated using the formula V = I × R
- The result is displayed with two decimal places for clarity


Written & researched by Dr. Shahin Siami