Enter number to begin with:125
List of prime numbers from 2 to < 125:
[113, 107, 101, 89, 79, 71, 61, 53, 43, 37, 29, 19, 13, 7, 3]
1+3, 1+7, 1+1, 8+9, 7+9....etc (single digits get added to themselves so for 7,3 it would be 7+7, 3+3)
How do I go through my list of every other prime and get those particular numbers to add?
Expand|Select|Wrap|Line Numbers
- def primes(n):
- """ returns a list of prime numbers from 2 to < n """
- if n < 2: return []
- if n == 2: return [2]
- # do only odd numbers starting at 3
- s = range(3, n, 2)
- # n**0.5 may be slightly faster than math.sqrt(n)
- mroot = n ** 0.5
- half = len(s)
- i = 0
- m = 3
- while m <= mroot:
- if s[i]:
- j = (m * m - 3)//2
- s[j] = 0
- while j < half:
- s[j] = 0
- j += m
- i = i + 1
- m = 2 * i + 3
- # make exception for 2
- return [2]+[x for x in s if x]
- num = input("Enter number you'd like to begin with:")
- primeList = primes(num)
- print "List of prime numbers from 2 to < %d:" % num
- a=primeList[1::2]
- print a