title: python define a variable in an if statement
body: <p>I want to make a coin toss / dice roll in python but i cannot figure out how to define / change a variable inside an if statement.</p>
  
  <pre><code>import random
  def roll(number):
      if(number==1):
          {print("Take a moment to think that through")}
      if(number==2):
          {b=random.randint(0,1)
          if(b=0):
              {ba=1}
          else:
              {bb=1}
          }
  </code></pre>
  
  <p>the part, <code>{b=random.randint(0,1)}</code> the <code>=</code> is highlighted red and marked as a syntax error. I also tried this:</p>
  
  <pre><code>import random
  b=0
  def roll(number):
      if(number==1):
          {print("Take a moment to think that through")}
      if(number==2):
          {b+=random.randint(0,1)
          if(b=0):
              {ba=1}
          else:
              {bb=1}
          }
  </code></pre>
  
  <p>that gives the same error, and the = is highlighted, not the +</p>
  
  <p>and before you ask, the function roll(number) is called in the shell. the shell is my interface.</p>