title: What's the difference between "if -if -else" and "if-elif-else"
body: <p><a href="https://www.hackerrank.com/challenges/grading/problem" rel="nofollow noreferrer">HackerRank: Grading Students</a></p>
  
  <p>when I typed this code:</p>
  
  <pre><code>def gradingStudents(grades):
      ls = []
      for grade in grades:
          if grade &lt;38:
              new_grade = grade
          else:
              n = grade //10
              t = grade % 10 
              if t &lt;5 and (5-t)&lt;3:
                  new_grade = n * 10 + 5
  
              if t &gt; 5 and (t - 5) &gt;2:
                  new_grade = (n+1) * 10
              else:
                  new_grade =grade
          ls.append(new_grade)   
      return ls
  </code></pre>
  
  <p>It's get the wrong answer.But when I changed the second if statement to elif,it's correct.I'm not very clear about what happened:</p>
  
  <pre><code> def gradingStudents(grades):
      ls = []
      for grade in grades:
          if grade &lt;38:
              new_grade = grade
          else:
              n = grade //10
              t = grade % 10 
              if t &lt;5 and (5-t)&lt;3:
                  new_grade = n * 10 + 5
  
              # I use "elif" replace "if"
              elif t &gt; 5 and (t - 5) &gt;2:
                  new_grade = (n+1) * 10
              else:
                  new_grade =grade
          ls.append(new_grade)   
      return ls
  </code></pre>