title: Python "ValueError: could not convert string to float: %"
body: <p>I have a set of instructions:</p>
  <p>Create a function called <code>format_change</code> which takes a string such as those in the Change column and does the following:</p>
  <ul>
  <li>If the last character is a <code>%</code> sign, remove it</li>
  <li>convert the string to a <strong>float</strong></li>
  <li>if that float is positive, multiply it by 100</li>
  <li>return the resulting <strong>float</strong></li>
  </ul>
  <p>This is my code:</p>
  <pre><code>def format_change(string):
      if string[-1] == &quot;%&quot;:
          string = string[-1]
  
      str_as_float = float(string)
  
      if str_as_float &gt; 0:
          str_as_float = str_as_float * 100
  
  return str_as_float
  </code></pre>
  <p>yet, when I enter the function</p>
  <pre class="lang-py prettyprint-override"><code>format_change(0.45%)
  </code></pre>
  <p>It returns the output:</p>
  <blockquote>
  <p>ValueError: could not convert string to float: '%'</p>
  </blockquote>
  <p>What can I do to convert it properly?</p>