This is by far my favorite interview question to give. In case the candidate may have memorized it, I might make a slight alteration. Like count backwards from 102 to 2 and don't print anything for prime numbers.
Isn't that harder than the actual question?
def is_prime(x):
if x%3 and x%2:
return True
else:
return False
print is_prime(4)
print is_prime(7)
EDIT: Oops, nevermind... you're all right and I'm wrong. I'm not fixing this code so everyone can see exactly how I screwed up.Edit: Perhaps you should keep this in mind next time you declare 99% of programmers incompetent because they made a typo when you asked them to write code down with pencil and paper in a high pressure interview situation.
It's amazing how much doing a few interviews inflates people egos.
"What's the first (positive) number my function will have wrong?"
Am I missing something, or is that basically what you're looking for?
So... actually, I don't know if it's filtering anything really. It's just interesting to watch people do it and it at least establishes that the candidate isn't a complete faker.