I've recently started trying to learn to code however i'm having a hard time when trying to build my own code. Any help would be greatly appreciated
The purpose of this code is to identify a prime number... i.e. the 20th prime number is 71. My problem is that my while loop does not end when p is no longer < 10.
- Code: Select all
## n = number being evaluated for primeness
p = 0 ##number of primes found
a = 0 ##anti prime - experimenting to avoid else statements
x = 3 ##is bumper to keep n increasing
##r is range for n calculations to determine divisibility.
while p < 10: #change this number for prime number required.
for n in range(2, 50): ##replace 50 with x to make an infinite loop
x = x + 1
print '\n\nEvaluating', n, 'for primeness:'
c = 0
for r in range(2, n): ##checking primeness
v = n%r
print n, '%', r, '=', v
if v == 0:
print n, ' is not a prime'
a = a + 1
print 'number of primes should be', n - a
p = n - a
print 'you suck meatballs, plus ', p, ' primes has been reached'
Thanks a billion in advance,