title: Error:string index out of range, defining a function
body: <p>I'm practicing coding on codingbat.com since I'm a complete beginner in python, and here is one of the exercises:</p>
  
  <p>Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo".</p>
  
  <p>Here is my attempt at defining the function string_bits(str):</p>
  
  <pre><code>def string_bits(str):
    char = 0
    first = str[char]
    for char in range(len(str)):
      char += 2
      every_other = str[char]
  return (first + every_other)
  </code></pre>
  
  <p>Running the code gives an error. What's wrong with my code?</p>