title: classes and methods python
body: <p>Im using python 3.6 and want to create a Interval class. I am trying to do an add method that can add an integer and an intervall. So far I managed to generate a code that works for 
  I=Interval(2,3) 
  c=I+1   #c=[3,4]</p>
  
  <p>however the opposite dosent work</p>
  
  <p>I=Interval(2,3)
  c=1+I #get the error message TypeError: unsupported operand type(s) for +: 'int' and 'Interval'</p>
  
  <p>my code for my class and method is as folow</p>
  
  <p>class Interval:</p>
  
  <pre><code>def __init__(self,start=None,end=None):
          if end==None:
              end=start
          if start==None:
              start=end
          if start&gt;end:
              raise TypeError('left value must be smaller than right value')
  
          self.start=start
          self.end=end
  </code></pre>
  
  <p>def <strong>add</strong> (self,other):</p>
  
  <pre><code>    if isinstance(other,int):    
          s2,e2=other,other
          s1,e1=self.start,self.end
  
      elif isinstance(self,int):
          s1,e1=self,self
          s2,e2=other.start,other.end
  
  
      else:
          s2,e2=other.start,other.end
          s1,e1=self.start,self.end
      return Interval(s1+s2,e1+e2)
  </code></pre>
  
  <p>if I try to change my elif in the add method to if nothing works. Does anyone know how to solve this?</p>
  
  <p>thanks!</p>