crosby0486

Simple code for Calculating Prime Constant

Apr 27th, 2021
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # Lists the Primes below 100
  2. first_p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
  3.  
  4. # Function built to find the smallest prime that does not divide a given number.
  5. def small_prime(num,prime):
  6.     return next((x for x in first_p if n % x != 0), "none")
  7.  
  8. # Variables
  9. n = 0
  10. prime_of_n = 2
  11. sum = 0
  12.  
  13. # User Prompt
  14. i = int(input('What number should we go to? '))
  15.  
  16. # While loop to compile all the values for the each number
  17. while True:
  18.     if n == i:
  19.         break
  20.     else:
  21.         n += 1
  22.         sum += small_prime(n,first_p)
  23.  
  24. # Prints result
  25. print('The average of these smallest primes that do not divide the numbers 1 to ',i,' is ',sum/n,'.')
  26.  
  27. # Inspired by Dr. James Grime in his video "2.920050977316" (https://youtu.be/_gCKX6VMvmU)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment