title: is it possible to have a variable amount of elifs in an if/elif/else chain?
body: <p>I am playing around with Markov-Chains and depending on the number of states I need the same amount of ifs.</p>
  <p>So if I happen to have a chain with 4 (from 0 to 3) states, my logic is as follows:</p>
  <pre><code>startingstate = &lt;is a variable&gt;
  
  if state == 0:
      change = &lt;some code that tells me what the state has changed to if it has&gt;
      if change == 0:
          &lt;do somethin01&gt;
      elif change == 1:
          &lt;do something1&gt;
      elif change == 2:
          &lt;do something2&gt;
      elif change == 3:
          &lt;do something3&gt;
  elif state == 1:
      &lt;same stuff as above&gt;
      
      and so on until we get to the last else of state == 3
  </code></pre>
  <p>Usually when I had such problems that required weird loop fiddling, there was some easier logic to get it done, but I cannot wrap my head around this. Do I have to go with a variable amount of elifs? If yes how do I do it? Or is there a better way?</p>
  <p>Thanks!:)</p>
  <p>My current attempt looks like this:</p>
  <pre><code>b = 3 #amount of possible states
  prob = 1 
  s= 0 #helper variable
  init_state = 0 
  state_list = []
  forecast = 6
  f = 0 
  
  while f != forecast:
      while s &lt; b:
          o=0 #helper variable
          if init_state == s:
              change = np.random.choice(transitionName[s],replace=True,p=transitionMatrix[s])
              print(change)
              while o &lt; b:
                  if change == transitionName[s][o]:
                      prob = prob * transitionMatrix[s][o]
                      init_state = o
                      print(prob)
                      state_list.append(s)
                  o+=1
          s+=1
      f+=1
  </code></pre>
  <p>with:</p>
  <pre><code>transitionName
  Out[83]: 
  [['0 to 0', '0 to 1', '0 to 2'],
   ['1 to 0', '1 to 1', '1 to 2'],
   ['2 to 0', '2 to 1', '2 to 2']]
  
  transitionMatrix
  Out[84]: 
  [[0.8333333333333334, 0.1111111111111111, 0.05555555555555555],
   [1.0, 0.0, 0.0],
   [0.3333333333333333, 0.0, 0.6666666666666666]]
  </code></pre>
  <p>this code is supposed to fill the state_list  with 6 states, as forecast = 6.  Somewhere something is wonky though and it only works if the state following the current state is different than the current state. How do I have to rearrange the loops so that I will always get forecast amount of items in state_list ?</p>