title: iterator in python that should print 10 valid id numbers
body: <p>Below is my code so far,The code should implement an iterator that prints 10 valid  IDs as at the condition at check_id function .</p>
  
  <p><a href="https://www.codepile.net/pile/b1PVdbBq" rel="nofollow noreferrer">https://www.codepile.net/pile/b1PVdbBq</a></p>
  
  <p>The output should be:
  123456782
  123456790
  123456808
  123456816
  123456824
  123456832
  123456840
  123456857
  123456865
  123456873
  but  somehow the my output is  wrong...help...</p>
  
  <pre><code>import string
  letters = string.ascii_letters
  digits = string.digits
  
  
  class NumNotNineLong(Exception):
  
      def __init__(self):
          pass
      def __str__(self):
          return "The number you provided is not nine digits long."
  
  class NotNumber(Exception):
  
      def __init__(self):
          pass
  
      def __str__(self):
          return "The input you provided is not an integer"
  
  class IDIterator():
  
      increment = 1
  
      def __init__(self,_id):
          self._id = _id  
  
      def __iter__(self):
         return self 
  
      def __next__(self):
  
          while check_id_valid(str(self._id)[-9::]) == False:
              self._id *= 2
              self._id += IDIterator.increment
              IDIterator.increment += 1
          if check_id_valid(str(self._id)[-9::]):
              result = str(self._id)[-9::]
              self._id *= 2
              self._id += 1
              IDIterator.increment = 2
              return result
  
  
  
  def check_id_valid(id_number): #A function that checks whether ID number are valid or not
      for letter in str(id_number):
          if letter not in string.digits:
              raise NotNumber
      numbers = [int(i) for i in str(id_number)]
      if len(numbers) != 9:
          raise NumNotNineLong
      set_numbers = []
      for i in range(len(numbers)):
          if i % 2 == 0:
              set_numbers.append(numbers[i])
          else:
              set_numbers.append(numbers[i] * 2)
      true_numbers = []
      for num in set_numbers:
          if num &gt; 9:
              temp = [int(i) for i in str(num)]
              true_numbers.append(sum(temp))
          else:
              true_numbers.append(num)
      if sum(true_numbers) % 10 == 0:
          return True
      else:
          return False
  
  def main():
      result = IDIterator(123456780)
      for _ in range(10):
          print(result.__next__())
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The exercise goes like this: a boolean function called check_id_valid that is defined as:
  def check_id_valid (id_number):
  The function obtains as an ID number (integer) parameter and returns a true boolean value (True), otherwise returns a false value (False).
  It works great when the check_id function is self-contained</p>
  
  <p>Then a class should be implemented to represent an iterator named IDIterator.</p>
  
  <p>This class has an attribute named id_ that represents an ID number in the range of 0 to 999999999 (this attribute is initialized when creating an iterator instance).</p>
  
  <p>The <strong>iter</strong> method that returns the iterator instance must be used in the above class.</p>
  
  <p>The <strong>next</strong> method that returns the next valid ID number in the range between id_ (inclusive) and 999999999 must be used in the above class.</p>
  
  <p>To check that the code you have written is working, write a master program with an iterator from the class you created.</p>
  
  <p>The iterator with the next ID value must be initialized 123456780, generate 10 new IDs and print them to the screen. Here is the output you should receive:</p>