Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. '''
  2. This module contains the functions to preform calculations using ohms law
  3. '''
  4.  
  5.  
  6. def calculate_voltage(resistance, amps):
  7. '''Calculates the voltage in a circuit given the resistance and amperage
  8.  
  9. :param resistance: Resistance value in ohms of wire/circuit
  10. :param amps: Current flowing through wire/circuit
  11. :return: Voltage
  12. '''
  13. return amps * resistance
  14.  
  15.  
  16. def calculate_current(volts, resistance):
  17. '''Calculates the current in a circuit given the voltage and resistance
  18.  
  19. :param volts: Voltage on wire
  20. :param resistance: Resistance value in ohms of wire/circuit
  21. :return: Current in amps
  22. '''
  23. return volts / resistance
  24.  
  25.  
  26. def calculate_resistance(volts, amps):
  27. '''Calculates the resistance in a circuit given the voltage and amperage
  28.  
  29. :param volts: Voltage on wire/circuit
  30. :param amps: Amps on wire/circuit
  31. :return: Resistance of wire/circuit
  32. '''
  33. return volts / amps
  34.  
  35. # ======
  36. # The functions below are for calculating the missing element in a circuit between volts, watts, and amps
  37. # with any 2 of those values the third can be calculated, use the functions below for thsoe calculations
  38.  
  39.  
  40. def watts_from_volts_amps(volts, amps):
  41. '''Calculates the wattage of a circuit given the circuits voltage and amperage
  42.  
  43. :param volts: Volts in circuit
  44. :param amps: Amps in circuit
  45. :return: Watts in circuit
  46. '''
  47. return amps * volts
  48.  
  49.  
  50. def amps_from_volts_watts(volts, watts):
  51. '''Calculates the amerage of a circuit given the circuits voltage and wattage
  52.  
  53. :param volts: Volts in circuit
  54. :param watts: Watts in circuit
  55. :return: Amps in circuit
  56. '''
  57. return watts / volts
  58.  
  59.  
  60. def volts_from_amps_watts(amps, watts):
  61. '''Calculates the voltage of a circuit given the known amperage and wattage
  62.  
  63. :param amps: Amps in circuit
  64. :param watts: Watts in circuit
  65. :return: Volts in circuit
  66. '''
  67.  
  68. return watts / amps
  69.  
  70. if __name__ == '__main__':
  71. print(calculate_resistance(volts=9, amps=1))
  72. print(watts_from_volts_amps(volts=5, amps=10))
  73. print(amps_from_volts_watts(volts=5, watts=50))
  74. print(volts_from_amps_watts(amps=10, watts=50))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement