Recently we had the question "Project Euler Problem #12 - Highly divisible triangular number"
It was closed as the OP included how to use the function with the function's code.
The code as posted fails to run due to
NameError: name 'num' is not definedon the last line. – Peter Taylor Apr 25 at 7:30
The function works, and so I don't think it should be closed as broken because of an
NameErrorin the example usage, because
numisn't declared. We allow this exception in other questions, even if half the program up for review is filled with them, not example input.
We shouldn't guess input to the function:
@Peilonrayz, which is what? The problem which this is attempting to solve is quite small and specific, so the code which solves it should run standalone without requiring the user to guess a value for an undocumented parameter. – Peter Taylor Apr 25 at 8:38
Another user in chat also held this view.
Because it takes a while on large inputs:
-1 from me because the Code does not solve the problem. I was not able to find the result. for small values of num the program finishes without printing a result and for larger numthe program hangs up without printing a result. – miracle173 Apr 26 at 16:18
Problems that exceed a time limit aren't off-topic on Code Review.
I don't think anyone's arguing for or against the first reason for closure. And the third has already been addressed. What should our views on the second be?
Should we close questions for naive implementations implementing limits, when they're not needed?
If you replace
for n in range(1,num) with
for n in itertools.count(1), then there would be no problem. Or if a user entered
float('inf') if they knew about it and if it worked with
range. They're a novice and doing the next best thing they know of.
numis undefined. \$\endgroup\$
numis excessive of course, because then it's obvious that you can just replace
numwith any value. Otherwise, I agree with 1201ProgramAlarm. \$\endgroup\$
assert fn(5) == 10, but it failed, then that would be off-topic as it wouldn't work as intended. But that would be
fnthat has the problem, not the unit test.
print(fn(a))doesn't say anything about
fnand so you wouldn't say the question is off topic because
ais undefined. \$\endgroup\$
numthat I can plug in to see that it works. And tell me how Long I have to wait until I see a result. \$\endgroup\$