Advertisement
MGakowski

Prime Finder

Dec 30th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. __author__ = 'Cyph3r'
  2. import math
  3.  
  4. f = str(input("Filename?"))
  5. text_file = open(f+".txt", "w")
  6. n = int(input("Limit? "))  # Limit Number
  7. x = int(input("Start? "))  # Starting Number
  8. a = int(math.sqrt(x))+1  # Working number
  9.  
  10. while x != n:
  11.  
  12.     if x % a != 0:  # Not equal divide
  13.         if a != 1:  # Check if (a) not at bottom of list
  14.             a -= 1
  15.         if a == 1:  # Check if (a) is at bottom of list
  16.             text_file.write(str(x)+"\n")
  17.             print(str(x)+" is Prime!")
  18.             x += 1
  19.  
  20.     if x % a == 0:  # If Equal divide, skip
  21.         x += 1
  22.         a = int(math.sqrt(x))+1
  23. text_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement