SHOW:
|
|
- or go back to the newest paste.
1 | #Name: | |
2 | #Date: 6 November 2014 | |
3 | #Assignment: While Loop | |
4 | ||
5 | - | print "Simple Text Ohm's Law Calculator" |
5 | + | def ohms_law(): |
6 | - | #user input |
6 | + | print "Simple Text Ohm's Law Calculator" |
7 | - | responseLoop = raw_input("Do you wish to perform a calculation? ('yes' or 'no') ") |
7 | + | #user input |
8 | - | #while loop |
8 | + | responseLoop = raw_input("Do you wish to perform a calculation? ('yes' or 'no') ") |
9 | - | while responseLoop == "yes": |
9 | + | #while loop |
10 | - | responseOhm = input("Enter 1 for voltage, 2 for current, or 3 for resistance: ") |
10 | + | while responseLoop == "yes": |
11 | - | if (responseOhm == 1): |
11 | + | responseOhm = input("Enter 1 for voltage, 2 for current, or 3 for resistance: ") |
12 | - | current = input("Please enter the current: ") |
12 | + | if (responseOhm == 1): |
13 | - | resist = input("Please enter the resistance: ") |
13 | + | current = input("Please enter the current: ") |
14 | - | volts = current * resist |
14 | + | resist = input("Please enter the resistance: ") |
15 | - | print "The voltage is:" , volts |
15 | + | volts = current * resist |
16 | - | elif (responseOhm == 2): |
16 | + | print "The voltage is:" , volts |
17 | - | volts = input("Please enter the voltage: ") |
17 | + | elif (responseOhm == 2): |
18 | - | resist = input("Please enter the resistance: ") |
18 | + | volts = input("Please enter the voltage: ") |
19 | - | current = volts/resist |
19 | + | resist = input("Please enter the resistance: ") |
20 | - | print "The current is:" , current |
20 | + | current = volts/resist |
21 | - | elif (responseOhm == 3): |
21 | + | print "The current is:" , current |
22 | - | volts = input("Please enter the voltage: ") |
22 | + | elif (responseOhm == 3): |
23 | - | current = input("Please enter the current: ") |
23 | + | volts = input("Please enter the voltage: ") |
24 | - | resist = volts/current |
24 | + | current = input("Please enter the current: ") |
25 | - | print "The resistance is:" , resist |
25 | + | resist = volts/current |
26 | - | else: |
26 | + | print "The resistance is:" , resist |
27 | - | print "Invalid response." |
27 | + | else: |
28 | - | responseLoop = raw_input("Do you wish to perform another calculation? ('yes' or 'no') ") |
28 | + | print "Invalid response." |
29 | - | print "End of program.” |
29 | + | responseLoop = raw_input("Do you wish to perform another calculation? ('yes' or 'no') ") |
30 | print "End of program.” | |
31 | ||
32 | if __name__ == '__main__': | |
33 | ohms_law() |