Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- This module contains the functions to preform calculations using ohms law
- '''
- def calculate_voltage(resistance, amps):
- '''Calculates the voltage in a circuit given the resistance and amperage
- :param resistance: Resistance value in ohms of wire/circuit
- :param amps: Current flowing through wire/circuit
- :return: Voltage
- '''
- return amps * resistance
- def calculate_current(volts, resistance):
- '''Calculates the current in a circuit given the voltage and resistance
- :param volts: Voltage on wire
- :param resistance: Resistance value in ohms of wire/circuit
- :return: Current in amps
- '''
- return volts / resistance
- def calculate_resistance(volts, amps):
- '''Calculates the resistance in a circuit given the voltage and amperage
- :param volts: Voltage on wire/circuit
- :param amps: Amps on wire/circuit
- :return: Resistance of wire/circuit
- '''
- return volts / amps
- # ======
- # The functions below are for calculating the missing element in a circuit between volts, watts, and amps
- # with any 2 of those values the third can be calculated, use the functions below for thsoe calculations
- def watts_from_volts_amps(volts, amps):
- '''Calculates the wattage of a circuit given the circuits voltage and amperage
- :param volts: Volts in circuit
- :param amps: Amps in circuit
- :return: Watts in circuit
- '''
- return amps * volts
- def amps_from_volts_watts(volts, watts):
- '''Calculates the amerage of a circuit given the circuits voltage and wattage
- :param volts: Volts in circuit
- :param watts: Watts in circuit
- :return: Amps in circuit
- '''
- return watts / volts
- def volts_from_amps_watts(amps, watts):
- '''Calculates the voltage of a circuit given the known amperage and wattage
- :param amps: Amps in circuit
- :param watts: Watts in circuit
- :return: Volts in circuit
- '''
- return watts / amps
- if __name__ == '__main__':
- print(calculate_resistance(volts=9, amps=1))
- print(watts_from_volts_amps(volts=5, amps=10))
- print(amps_from_volts_watts(volts=5, watts=50))
- print(volts_from_amps_watts(amps=10, watts=50))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement