Suppenbiatch

my first python prime number tester

Feb 9th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import math
  2. import keyboard
  3. import progressbar
  4.  
  5. input_num = input("Number to Test: ")
  6. test_number = int(input_num)
  7. max_num_to_test = int(math.sqrt(test_number)+ 1)
  8. nums_found = 0
  9.  
  10.  
  11.  
  12. for i in progressbar.progressbar(range(2,max_num_to_test), redirect_stdout=True):
  13.     num = test_number%i
  14.     try:
  15.         if keyboard.is_pressed('i'):
  16.             if not was_pressed:
  17.                 was_pressed = True
  18.                 print("Found:", nums_found, "divider, testing:",max_num_to_test-i, "more numbers.")
  19.         else:
  20.             was_pressed = False
  21.         if keyboard.is_pressed('q'):
  22.             break
  23.     except:
  24.         pass
  25.     if num == 0:
  26.         print(test_number, "can be divided by:", i)
  27.         nums_found = nums_found + 1
  28.        
  29. if nums_found == 0:
  30.     print(test_number, "is a prime.")
  31. else:
  32.     print("Found:", nums_found)
  33.    
  34. print("DONE TESTING")
  35. dont_just_end = input("press any key to exit")
Add Comment
Please, Sign In to add comment