Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Name:
  2. #Date: 6 November 2014
  3. #Assignment: While Loop
  4.  
  5. def ohms_law():
  6. print "Simple Text Ohm's Law Calculator"
  7. #user input
  8. responseLoop = raw_input("Do you wish to perform a calculation? ('yes' or 'no') ")
  9. #while loop
  10. while responseLoop == "yes":
  11. responseOhm = input("Enter 1 for voltage, 2 for current, or 3 for resistance: ")
  12. if (responseOhm == 1):
  13. current = input("Please enter the current: ")
  14. resist = input("Please enter the resistance: ")
  15. volts = current * resist
  16. print "The voltage is:" , volts
  17. elif (responseOhm == 2):
  18. volts = input("Please enter the voltage: ")
  19. resist = input("Please enter the resistance: ")
  20. current = volts/resist
  21. print "The current is:" , current
  22. elif (responseOhm == 3):
  23. volts = input("Please enter the voltage: ")
  24. current = input("Please enter the current: ")
  25. resist = volts/current
  26. print "The resistance is:" , resist
  27. else:
  28. print "Invalid response."
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement