#!/usr/bin/env python
import math
def primeTest(isPrime):
print(' {0}=testnum'.format(testnum))
if testnum%2 == 0 and testnum != 2: #if divisible by 2 and not 2
isPrime = False
print('{0} a'.format(isPrime))
print('a')
else:
numroot = round(math.sqrt(testnum))
i = 2
while i <= numroot:
if testnum%i == 0:
isPrime = False
i+=1
print('b')
global testnum
global isPrime
testnum=2
numPrimesSoFar=0
reqPrimes=int(input('How many primes would you like? \n'))
while numPrimesSoFar < reqPrimes:
isPrime=True
primeTest(isPrime)
print(isPrime)
if isPrime:
print(' {0}'.format(isPrime))
print(' {0}'.format(testnum))
numPrimesSoFar+=1
testnum+=1
(sorry about the formatting I'm not really sure why it's not working right, but assume I have the tab-formatting correct) Now this outputs this:
How many primes would you like?
4
2=testnum
b
True
True
2
3=testnum
b
True
True
3
4=testnum
False a
a
True
True
4
5=testnum
b
True
True
5
Alright... so why is isPrime true still when I set it to false?
EDIT: Okay... so is THAT what you guys are talking about?