GentleClash

primeNumbers.py

Mar 23rd, 2023 (edited)
86
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | Source Code | 0 0
  1. import numpy as np
  2. from math import sqrt
  3.  
  4. limit=int(input("Prime numbers upto: "))
  5. y=[] #This list will contain prime numbers
  6.  
  7. #Generating a list of all numbers upto entered limits
  8.  
  9. x=np.arange(1,limit+1)
  10.  
  11. #Lambda function takes x and returns
  12. #True if the list containing multiples of passed x is 0.
  13. #Here, I have used list comprehension to do so.
  14.  
  15. prime=lambda x: len([i for i in range(2,int(sqrt(x)+1)) if (x%i)==0])==0
  16.  
  17. #Filter out numbers from array x and print them as list
  18.  
  19. y=list(filter(prime,x))
  20. print(y)
Advertisement
Comments
Add Comment
Please, Sign In to add comment