Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. class PrimeNumbers(object):
  2.  
  3.     def __init__(self, max):
  4.         if max < 2:
  5.             raise ValueError("max should be >= 2")
  6.         self.max = max
  7.         self.cur = 2
  8.  
  9.      def __next__(self):
  10.         while self.cur <= max:
  11.             for i in range(2, self.cur):
  12.                 if self.cur % i == 0:
  13.                     break
  14.             else:
  15.                 return self.cur
  16.  
  17.             self.cur += 1
  18.  
  19.      def __iter__(self):
  20.         return self
  21.  
  22.  
  23. if __name__ == '__main__':
  24.     for i in PrimeNumbers(100):
  25.         print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement