prompt: I am working in python and trying to solve this programming prompt:
  
  You are provided with a list (or array) of integer pairs. Elements of each pair represent the number of people that get on the bus (the first item) and the number of people that get off the bus (the second item) at a bus stop.
  
  Your task is to return the number of people who are still on the bus after the last bus stop (after the last array). 
  
  Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the returned integer can't be negative.
  
  The second value in the first pair in the array is 0, since the bus is empty in the first bus stop.
  
  Here is my code I have
  
  def number(bus_stops):
      for on, off in bus_stops:
          total = 0
          total += on
          total -= off
      return total
  
  But it doesn't work. Can you tell me what is wrong with it?
chosen.role: system
chosen.content: A chat.
chosen.role: user
chosen.content: I am working in python and trying to solve this programming prompt:
  
  You are provided with a list (or array) of integer pairs. Elements of each pair represent the number of people that get on the bus (the first item) and the number of people that get off the bus (the second item) at a bus stop.
  
  Your task is to return the number of people who are still on the bus after the last bus stop (after the last array). 
  
  Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the returned integer can't be negative.
  
  The second value in the first pair in the array is 0, since the bus is empty in the first bus stop.
  
  Here is my code I have
  
  def number(bus_stops):
      for on, off in bus_stops:
          total = 0
          total += on
          total -= off
      return total
  
  But it doesn't work. Can you tell me what is wrong with it?
chosen.role: assistant
chosen.content: The issue with your code is that the initialization of total is in the wrong scope. The way the code is now, the total variable will be set to zero on every loop iteration, thus resetting it. To fix the issue, move the line "total = 0". Here is the modified code:
  
  def number(bus_stops):
      total = 0
      for on, off in bus_stops:
          total += on
          total -= off
      return total
rejected.role: system
rejected.content: A chat.
rejected.role: user
rejected.content: I am working in python and trying to solve this programming prompt:
  
  You are provided with a list (or array) of integer pairs. Elements of each pair represent the number of people that get on the bus (the first item) and the number of people that get off the bus (the second item) at a bus stop.
  
  Your task is to return the number of people who are still on the bus after the last bus stop (after the last array). 
  
  Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the returned integer can't be negative.
  
  The second value in the first pair in the array is 0, since the bus is empty in the first bus stop.
  
  Here is my code I have
  
  def number(bus_stops):
      for on, off in bus_stops:
          total = 0
          total += on
          total -= off
      return total
  
  But it doesn't work. Can you tell me what is wrong with it?
rejected.role: assistant