Conversor de Resistência Elétrica
Converta entre ohm, miliohm, micro-ohm, kilohm, megaohm e gigaohm.
Conversion Results
Ohm (Omega)
1
Milliohm (mOhm)
1000
Microohm (uOhm)
1000000
Kilohm (kOhm)
0.001
Megaohm (MOhm)
0.000001
Gigaohm (GOhm)
1e-9
Perguntas Frequentes
Implementação de Código
# Electric resistance unit converter
CONVERSION_FACTORS = {
'ohm': 1,
'milliohm': 1e-3,
'microohm': 1e-6,
'kilohm': 1e3,
'megaohm': 1e6,
'gigaohm': 1e9,
}
def convert_resistance(value: float, from_unit: str, to_unit: str) -> float:
"""Convert between resistance units"""
if from_unit not in CONVERSION_FACTORS:
raise ValueError(f"Unknown unit: {from_unit}")
if to_unit not in CONVERSION_FACTORS:
raise ValueError(f"Unknown unit: {to_unit}")
# Convert to ohm first, then to target
in_ohm = value * CONVERSION_FACTORS[from_unit]
return in_ohm / CONVERSION_FACTORS[to_unit]
def display_all(value: float, unit: str):
"""Show value in all units"""
for target_unit, factor in CONVERSION_FACTORS.items():
converted = convert_resistance(value, unit, target_unit)
print(f" {converted:.6g} {target_unit}")
# Ohm's law
def ohms_law(voltage=None, current=None, resistance=None):
"""Calculate the missing value using V = I * R"""
if voltage is None:
return current * resistance
if current is None:
return voltage / resistance
return voltage / current
# Examples
print("1 kilohm =")
display_all(1, 'kilohm')
print(f"V=5V, R=1kOhm -> I={ohms_law(voltage=5, resistance=1000)*1000:.1f} mA")
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.