DEV Community

sumit78648786
sumit78648786

Posted on

Ohms calculator using python

Today I written a calculator program to calculate the ohms formula by python programming language...
If you found better way to write it again please let me know directly message me or comment me.

here program starts.

print ("""ohms calculator v1.0
""")
print("""Please enter only numbers unless it will show you an error
""")
print("""Enter minimum 2 values
""")
v=input(str('[Enter value of V]: '))
i=input(str('[Enter value of I]: '))
r=input(str('[Enter value of R]: '))
op=input(str("""[Enter 1 to calculate voltage]

[Enter 2 to calculate Ampere]

[Enter 3 to calculate Resistance]
"""))
if op=='1':
print(int(i)*int(r))
elif op=='2':
print(int(v)/int(r))
elif op=='3':
print(int(v)/int(i))

Top comments (1)

Collapse
 
j_mplourde profile image
Jean-Michel Plourde • Edited

This is a very good start. I can see that there would be a problem if I entered a resistance of 0 then selected to calculate the voltage. There should be a try/catch or division by zero verification.