@pysnooper.snoop() deffindPrimes(number): num = 2 primes = [] while num <= number: div = 2 flag = True while div * div <= num and flag: if num % div == 0: flag = False div = div + 1 if flag: primes.insert(len(primes), num) num = num + 1 return primes print(findPrimes(10))
@pysnooper.snoop("./debug1.log") defisPrime(num): div = 2 while div * div <= num: if num % div == 0: returnFalse div = div + 1 returnTrue
@pysnooper.snoop("./debug.log") deffindPrimes(number): num = 2 primes = [] while num <= number: if isPrime(num): primes.insert(len(primes), num) num = num + 1 return primes print(findPrimes(10))
@pysnooper.snoop("./debug.log", prefix="--isPrime--") defisPrime(num): div = 2 while div * div <= num: if num % div == 0: returnFalse div = div + 1 returnTrue
@pysnooper.snoop("./debug.log", prefix="--findPrimes--") deffindPrimes(number): num = 2 primes = [] while num <= number: if isPrime(num): primes.insert(len(primes), num) num = num + 1 return primes print(findPrimes(10))
defisPrime(num): div = 0 while div * div <= num: if num % div == 0: returnFalse div = div + 1 returnTrue
deffindPrimes(number): num = 2 primes = [] while num <= number: if isPrime(num): primes.insert(len(primes), num) num = num + 1 return primes print(findPrimes(10))
執行之後產生以下的 Crash info
1 2 3 4 5 6 7 8
Traceback (most recent call last): File "a.py", line 20, in <module> print(findPrimes(10)) File "a.py", line 16, in findPrimes if isPrime(num): File "a.py", line 7, in isPrime if num % div == 0: ZeroDivisionError: integer division or modulo by zero
defisPrime(num): div = 0 while div * div <= num: if num % div == 0: returnFalse div = div + 1 returnTrue
deffindPrimes(number): num = 2 primes = [] while num <= number: if isPrime(num): primes.insert(len(primes), num) num = num + 1 return primes print(findPrimes(10))
File a.py, line 20, in <module> 16 if isPrime(num): 17 primes.insert(len(primes), num) 18 num = num + 1 19 return primes --> 20 print(findPrimes(10))
File a.py, line 16, in findPrimes 12 def findPrimes(number): 13 num = 2 14 primes = [] 15 while num <= number: --> 16 if isPrime(num): 17 primes.insert(len(primes), num) .................................................. number = 10 num = 2 primes = [] ..................................................
File a.py, line 7, in isPrime 4 def isPrime(num): 5 div = 0 6 while div * div <= num: --> 7 if num % div == 0: 8 return False .................................................. num = 2 div = 0 ..................................................
ZeroDivisionError: integer division or modulo by zero