View difference between Paste ID: rhTqmUq1 and 7bxZffcK
SHOW: | | - or go back to the newest paste.
1
2
class Power(float):
3-
    def __init__(self):
3+
    phys_unit = 'Watt'
4-
        self.phys_unit = 'Watt'
4+
    formal_letter = 'P'
5-
        self.formal_letter = 'P'
5+
    abbreviation = 'W'
6-
        self.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-
    def __init__(self):
20+
    formal_letter = 'R'
21-
        self.phys_unit = 'Ohm'
21+
    # abbreviation = 'Ω'
22-
        self.formal_letter = 'R'
22+
23-
        self.abbreviation = 'Ω'
23+
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-
    def __init__(self):
34+
    abbreviation = 'A'
35-
        self.phys_unit = 'Ampere'
35+
36-
        self.formal_letter = 'I'
36+
37-
        self.abbreviation = 'A'
37+
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-
    def __init__(self):
47+
48-
        self.phys_unit = 'Volt'
48+
49-
        self.formal_letter = 'U'
49+
50-
        self.abbreviation = 'V'
50+
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)