title: operation on a variable inside a class in python
body: <p>I'm new with oop and python. I've been trying to do a simple thing:
  there is class called Foo(),it contains a variable called x which is initially set to zero.</p>
  
  <pre><code>&gt;&gt;&gt;a = Foo()
  &gt;&gt;&gt;a.x
  &gt;&gt;&gt;0 
  </code></pre>
  
  <p>now I want to give a new value to x so:</p>
  
  <pre><code>&gt;&gt;&gt;p.x = 1983
  </code></pre>
  
  <p>now a math operation should happen to x, for instance 1 is add to x.now x is 1984,so now when I call x:</p>
  
  <pre><code>&gt;&gt;&gt; p.x
  &gt;&gt;&gt; 1984
  </code></pre>
  
  <p>also the program should check that whether or not the value given to x is negative or not.If it is negative it should return -1.
  I did this but it didn't work:(as I said it should do some mathematical operation on x,the operation itself is not really important)</p>
  
  <pre><code>class Foo():
      x = 0
      if x &gt; 0:
          x %= 100
      elif x &lt; 0:
          x = -1
  </code></pre>
  
  <p>I really don't now how should I update a class variable in they I mentioned.
  Thank you very much for your attention.</p>