Advertisement
naren_paste

Prime Generator

Aug 2nd, 2023
1,036
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | Science | 0 0
  1. def is_prime(num):
  2.     if num < 2:
  3.         return False
  4.     for i in range(2, int(num ** 0.5) + 1):
  5.         if num % i == 0:
  6.             return False
  7.     return True
  8. def prime_generator(limit):
  9.     num = 2
  10.     while num < limit:
  11.         if is_prime(num):
  12.             yield num
  13.         num += 1
  14.  
  15. prime_gen = prime_generator(1000)
  16. print("First 20 prime numbers:")
  17. for _ in range(20):
  18.     print(next(prime_gen))
Advertisement
Comments
  • millardmillion
    305 days
    # text 0.31 KB | 0 1
    1. How to play slot machine with good and fair with good agent only at here KINGSAN168. because at here will give you good advice play on which game and which game player have good ratio on winning play. dont hestitate to play at here buddy. #kingsan168 or can visit our website for more infomation https://kingsan168.com/
Add Comment
Please, Sign In to add comment
Advertisement