Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PrimeNumbers(object):
- def __init__(self, max):
- if max < 2:
- raise ValueError("max should be >= 2")
- self.max = max
- self.cur = 2
- def __next__(self):
- while self.cur <= max:
- for i in range(2, self.cur):
- if self.cur % i == 0:
- break
- else:
- return self.cur
- self.cur += 1
- def __iter__(self):
- return self
- if __name__ == '__main__':
- for i in PrimeNumbers(100):
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement