Hacker News new | ask | show | jobs
by jamii 5384 days ago
For some reason this is the most common mistake I see from students:

    for i in range(0,n):
      if i % 3 == 0:
        print 'fizz'
      elif i % 5 == 0:
        print 'buzz'
      elif (i % 3 == 0) and (i % 5 == 0):
        print 'fizzbuzz'
      else
        print i
It's not so much arithmetic that's the problem but reasoning about overlapping boolean conditions.
2 comments

Hmmm.. I see. Is this done on a whiteboard? If you let them use an editor and run it and they fixed it right away would that be acceptable?

I wonder if people are getting such bad results on this because it's always the first question they ask and the candidate isn't comfortable yet.

Agreed. When we see people trip up it's often becaues of this.

I think the problem is the old adage about not being able to to see the forest for the trees.

They break it down to the simple components and write those fairly easily but the forget about big picture of all 3 conditions working together.