Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Lists the Primes below 100
- 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]
- # Function built to find the smallest prime that does not divide a given number.
- def small_prime(num,prime):
- return next((x for x in first_p if n % x != 0), "none")
- # Variables
- n = 0
- prime_of_n = 2
- sum = 0
- # User Prompt
- i = int(input('What number should we go to? '))
- # While loop to compile all the values for the each number
- while True:
- if n == i:
- break
- else:
- n += 1
- sum += small_prime(n,first_p)
- # Prints result
- print('The average of these smallest primes that do not divide the numbers 1 to ',i,' is ',sum/n,'.')
- # Inspired by Dr. James Grime in his video "2.920050977316" (https://youtu.be/_gCKX6VMvmU)
Advertisement
Add Comment
Please, Sign In to add comment