Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Name:
- #Date: 6 November 2014
- #Assignment: While Loop
- def ohms_law():
- print "Simple Text Ohm's Law Calculator"
- #user input
- responseLoop = raw_input("Do you wish to perform a calculation? ('yes' or 'no') ")
- #while loop
- while responseLoop == "yes":
- responseOhm = input("Enter 1 for voltage, 2 for current, or 3 for resistance: ")
- if (responseOhm == 1):
- current = input("Please enter the current: ")
- resist = input("Please enter the resistance: ")
- volts = current * resist
- print "The voltage is:" , volts
- elif (responseOhm == 2):
- volts = input("Please enter the voltage: ")
- resist = input("Please enter the resistance: ")
- current = volts/resist
- print "The current is:" , current
- elif (responseOhm == 3):
- volts = input("Please enter the voltage: ")
- current = input("Please enter the current: ")
- resist = volts/current
- print "The resistance is:" , resist
- else:
- print "Invalid response."
- responseLoop = raw_input("Do you wish to perform another calculation? ('yes' or 'no') ")
- print "End of program.”
- if __name__ == '__main__':
- ohms_law()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement