fork download
  1. import math
  2.  
  3. def isPrime (primeList, candidate):
  4. prime = True
  5. i = 0
  6. upperLimit = math.sqrt(j)
  7. while primeList[i] <= upperLimit and prime:
  8. if candidate % primeList[i] == 0:
  9. prime = False
  10. i +=1
  11. return prime
  12.  
  13. def primeList(listLength):
  14. if listLength < 1 :
  15. return []
  16. primeList = [2]
  17.  
  18. candidate = 3
  19. while listLength > len(primeList):
  20. candidate +=2
  21. if isPrime(primeList, candidate):
  22. primeList.append(candidate)
  23.  
  24. return primeList
  25.  
  26. primeList(10000)
Runtime error #stdin #stdout #stderr 0.08s 8832KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 26, in <module>
    primeList(10000)
  File "prog.py", line 21, in primeList
    if isPrime(primeList, candidate):
  File "prog.py", line 6, in isPrime
    upperLimit = math.sqrt(j)
NameError: global name 'j' is not defined