Advertisement
Brainsucker

Untitled

Sep 3rd, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class Power(float):
  3.     phys_unit = 'Watt'
  4.     formal_letter = 'P'
  5.     abbreviation = 'W'
  6.        
  7.     def __mul__(self, other):
  8.         pass
  9.    
  10.     def __div__(self, other):
  11.         if isinstance(other, Voltage):
  12.             return Current(self / other)
  13.            
  14.         elif isinstance(other, Current):
  15.             return Voltage(self / other)
  16.  
  17.  
  18. class Resistance(float):
  19.     phys_unit = 'Ohm'
  20.     formal_letter = 'R'
  21.     # abbreviation = 'Ω'
  22.        
  23.     def __mul__(self, other):
  24.         if isinstance(other, Current):
  25.             return Voltage(self * other)
  26.        
  27.     def __div__(self, other):
  28.         pass
  29.  
  30.  
  31. class Current(float):
  32.     phys_unit = 'Ampere'
  33.     formal_letter = 'I'
  34.     abbreviation = 'A'
  35.      
  36.     def __mul__(self, other):
  37.         if isinstance(other, Voltage):
  38.             return Power(self * other)
  39.    
  40.     def __div__(self, other):
  41.         pass
  42.  
  43. class Voltage(float):
  44.     phys_unit = 'Volt'
  45.     formal_letter = 'U'
  46.     abbreviation = 'V'
  47.  
  48.     def __mul__(self, other):
  49.         if isinstance(other, Current):
  50.             return Power(self * other)
  51.            
  52.            
  53.     def __div__(self, other):
  54.         if isinstance(other, Current):
  55.             return Resistance(self / other)
  56.            
  57.         elif isinstance(other, Resistance):
  58.             return Current(self / other)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement