zlacker

[return to "My Favorite Programming Problem to Teach: Digit Length"]
1. _paste+Id[view] [source] 2019-11-11 00:48:19
>>jstrie+(OP)
Why not:

  def digit_len(n): 
    return len(str(n))
◧◩
2. crummy+Ud[view] [source] 2019-11-11 00:51:40
>>_paste+Id
That's mentioned in the article, at the bottom, under the topic "Alternative, invalid solution":

> As a result, solutions using strings are disallowed on problem sets and quizzes until they are taught.

◧◩◪
3. lvncel+qL[view] [source] 2019-11-11 09:46:44
>>crummy+Ud
Also as a result, even the proposed solution is wrong for certain cases, takes longer, and doesn't convey what it's achieving as elegantly as `len(str(n))`. Because the length of the string representation is - exactly - what is being asked here.

I get that sometimes the simplest solution to a problem is not teaching the right stuff, but in almost all cases that is a fault in the problem, not the solution.

[go to top]