title: Im getting an index error and im not sure why
body: <p>So ive been working on a script for a course im doing and ive ran into an error</p>
  
  <p>The basic idea of the program is a voting system but when working out who got the most votes the program hits an error the error reads </p>
  
  <pre><code>    if votes[0] &gt; votes[1] and votes[0] &gt; votes[2] and votes[0] &gt; votes[3]:
  IndexError: list index out of range
  </code></pre>
  
  <p>The full funtion is here:</p>
  
  <pre><code>def getwinner():
      if votes[0] &gt; votes[1] and votes[0] &gt; votes[2] and votes[0] &gt; votes[3]:
          print("Congratulations candidate",cands[0],"You win")
          if votes[1] &gt; votes[0] and votes[1] &gt; votes[2] and votes[1] &gt; votes[3]:
              print("Congratulations candidate", cands[1], "You win")
              if votes[2] &gt; votes[0] and votes[2] &gt; votes[1] and votes[2] &gt; votes[3]:
                  print("Congratulations candidate", cands[2], "You win")
                  if votes[3] &gt; votes[0] and votes[3] &gt; votes[1] and votes[3] &gt; votes[2]:
                      print("Congratulations candidate", cands[3], "You win")
  
                      if votes[0] == votes[1] and votes[0] == votes[2] and votes[0] == votes[3]:
                          print("We have a tie")
                          if votes[1] == votes[0] and votes[1] == votes[2] and votes[1] == votes[3]:
                              print("We have a tie")
                              if votes[2] == votes[0] and votes[2] == votes[1] and votes[2] == votes[3]:
                                  print("We have a tie")
                                  if votes[3] == votes[0] and votes[3] == votes[1] and votes[3] == votes[2]:
                                      print("We have a tie")
  </code></pre>
  
  <p>The votes are saved to an array called "votes" and candidate names are saved to "cands".The candidate names line up with the votes in the "votes" array. But could someone explain the issue and also is there a simpler, less long winded way of going about this? Thanks</p>