Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Power(float):
- phys_unit = 'Watt'
- formal_letter = 'P'
- abbreviation = 'W'
- def __mul__(self, other):
- pass
- def __div__(self, other):
- if isinstance(other, Voltage):
- return Current(self / other)
- elif isinstance(other, Current):
- return Voltage(self / other)
- class Resistance(float):
- phys_unit = 'Ohm'
- formal_letter = 'R'
- # abbreviation = 'Ω'
- def __mul__(self, other):
- if isinstance(other, Current):
- return Voltage(self * other)
- def __div__(self, other):
- pass
- class Current(float):
- phys_unit = 'Ampere'
- formal_letter = 'I'
- abbreviation = 'A'
- def __mul__(self, other):
- if isinstance(other, Voltage):
- return Power(self * other)
- def __div__(self, other):
- pass
- class Voltage(float):
- phys_unit = 'Volt'
- formal_letter = 'U'
- abbreviation = 'V'
- def __mul__(self, other):
- if isinstance(other, Current):
- return Power(self * other)
- def __div__(self, other):
- if isinstance(other, Current):
- return Resistance(self / other)
- elif isinstance(other, Resistance):
- return Current(self / other)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement