-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathohm_law.py
More file actions
30 lines (27 loc) · 952 Bytes
/
Copy pathohm_law.py
File metadata and controls
30 lines (27 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Ohm law image: https://bit.ly/3MDmq74
def ohm_law():
"""ohm_law calculates the voltage, current or resistance depending on the choice
"""
print(''' \n¿What do you want to calculate?
1 Voltage
2 Current
3 Resistance
''')
option = int(input('Select an option: '))
while option <= 0 or option >= 4:
print('Invalid value')
option = int(input('Select an option: '))
else:
number1 = int(input('Enter the first value '))
number2 = int(input('Enter the second value '))
if option == 1:
voltage = number1 * number2
print(f'Voltage: {voltage:.2f}')
elif option == 2:
current = number1 / number2
print(f'Current: {current:.2f}')
elif option == 3:
resistance = number1 / number2
print(f'Resistance: {resistance:.2f}')
if __name__ == '__main__':
ohm_law()