(7): indentation error. But I guess the interpreter will tell you i is used out of scope. That, or you would have gotten another catastrophic result on numbers below 10.
def is_prime(n):
for i in range(2,n):
if n%i == 0: return False
return True
(Edit: okay, that was LessWrong screwing up leading spaces. We can cheat that with unbreakable spaces.)
Yes, good point. I’d generalize: “I could have committed some syntax error—wrong indentation, wrong sort of brackets somewhere, etc. -- that just happens to leave a program with correct syntax but unintended semantics.”
I guess the interpreter will tell you i is used out of scope.
Depends on exactly what error occurs. (With the formatting the way it actually looks here it would just be a syntax error.)
That, or you would have gotten another catastrophic result on numbers below 10.
This (aside from the simplicity of the code) is the real reason why I’m still happy with an error probability less than 0.001. It takes a really odd sort of error to produce correct results for the first 100 candidate primes and wrong results thereafter. I could write some programs with that sort of error, but they wouldn’t look at all like naive primality checkers with simple typos.
(7): indentation error. But I guess the interpreter will tell you
i
is used out of scope. That, or you would have gotten another catastrophic result on numbers below 10.(Edit: okay, that was LessWrong screwing up leading spaces. We can cheat that with unbreakable spaces.)
Yes, good point. I’d generalize: “I could have committed some syntax error—wrong indentation, wrong sort of brackets somewhere, etc. -- that just happens to leave a program with correct syntax but unintended semantics.”
Depends on exactly what error occurs. (With the formatting the way it actually looks here it would just be a syntax error.)
This (aside from the simplicity of the code) is the real reason why I’m still happy with an error probability less than 0.001. It takes a really odd sort of error to produce correct results for the first 100 candidate primes and wrong results thereafter. I could write some programs with that sort of error, but they wouldn’t look at all like naive primality checkers with simple typos.