Re: python interview quuestions

Discussion in 'Python' started by Tim Chase, Aug 7, 2010.

  1. Tim Chase

    Tim Chase Guest

    On 08/06/10 15:37, James Mills wrote:
    > On Sat, Aug 7, 2010 at 6:28 AM, geremy condra<> wrote:
    >> If I had to wait 5 minutes while a candidate tried to solve this
    >> problem I would not hire them.

    >
    > Yes you do raise a valid point. It should really only take
    > you a mere few seconds or so to write a solution to this.
    >
    > More over, it can be done in just a single line of Python.
    >
    > 7 if you're not very familiar with Python.


    While it *can* be done in one line, I'm not sure it's the most
    legible solution. Though I must say I like this one-line python
    version:

    for i in range(1, 101): print ((i%3==0 and 'fizz' or '') +
    (i%5==0 and 'buzz' or '')) or i

    (adjust "3" and "5" for your local flavor of fizzbuzz)

    I'm not sure I'd hire a candidate that proposed this as a
    solution in earnest, but I'd have fun chatting with them :)

    -tkc
    Tim Chase, Aug 7, 2010
    #1
    1. Advertising

  2. Tim Chase

    Peter Otten Guest

    Tim Chase wrote:

    > On 08/06/10 15:37, James Mills wrote:
    >> On Sat, Aug 7, 2010 at 6:28 AM, geremy condra<> wrote:
    >>> If I had to wait 5 minutes while a candidate tried to solve this
    >>> problem I would not hire them.

    >>
    >> Yes you do raise a valid point. It should really only take
    >> you a mere few seconds or so to write a solution to this.
    >>
    >> More over, it can be done in just a single line of Python.
    >>
    >> 7 if you're not very familiar with Python.

    >
    > While it *can* be done in one line, I'm not sure it's the most
    > legible solution. Though I must say I like this one-line python
    > version:
    >
    > for i in range(1, 101): print ((i%3==0 and 'fizz' or '') +
    > (i%5==0 and 'buzz' or '')) or i
    >
    > (adjust "3" and "5" for your local flavor of fizzbuzz)
    >
    > I'm not sure I'd hire a candidate that proposed this as a
    > solution in earnest, but I'd have fun chatting with them :)


    You mean you'd go for the candidate who took the conservative approach and
    got it right:

    print 1
    print 2
    print 'Fizz'
    print 4
    print 'Buzz'
    print 'Fizz'
    print 7
    print 8
    print 'Fizz'
    print 'Buzz'
    print 11
    print 'Fizz'
    print 13
    print 14
    print 'FizzBuzz'
    print 16
    print 17
    print 'Fizz'
    print 19
    print 'Buzz'
    print 'Fizz'
    print 22
    print 23
    print 'Fizz'
    print 'Buzz'
    print 26
    print 'Fizz'
    print 28
    print 29
    print 'FizzBuzz'
    print 31
    print 32
    print 'Fizz'
    print 34
    print 'Buzz'
    print 'Fizz'
    print 37
    print 38
    print 'Fizz'
    print 'Buzz'
    print 41
    print 42
    print 43
    print 44
    print 'FizzBuzz'
    print 46
    print 47
    print 'Fizz'
    print 49
    print 'Buzz'
    print 'Fizz'
    print 52
    print 53
    print 'Fizz'
    print 'Buzz'
    print 56
    print 'Fizz'
    print 58
    print 59
    print 'FizzBuzz'
    print 61
    print 62
    print 'Fizz'
    print 64
    print 'Buzz'
    print 'Fizz'
    print 67
    print 68
    print 'Fizz'
    print 'Buzz'
    print 71
    print 'Fizz'
    print 73
    print 74
    print 'FizzBuzz'
    print 76
    print 77
    print 'Fizz'
    print 79
    print 'Buzz'
    print 'Fizz'
    print 82
    print 83
    print 'Fizz'
    print 'Buzz'
    print 86
    print 'Fizz'
    print 88
    print 89
    print 'FizzBuzz'
    print 91
    print 92
    print 'Fizz'
    print 94
    print 'Buzz'
    print 'Fizz'
    print 97
    print 98
    print 'Fizz'
    print 'Buzz'

    Well, almost right, but one error per 100 lines at the first try is near-
    genius anyway...

    Peter
    Peter Otten, Aug 7, 2010
    #2
    1. Advertising

  3. Tim Chase

    Terry Reedy Guest

    On 8/7/2010 7:53 AM, Peter Otten wrote:

    >
    > You mean you'd go for the candidate who took the conservative approach and
    > got it right:
    >
    > print 1
    > print 2
    > print 'Fizz'
    > print 4
    > print 'Buzz'
    > print 'Fizz'
    > print 7
    > print 8
    > print 'Fizz'
    > print 'Buzz'


    Way too verbose. How about
    print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n
    etc.

    --
    Terry Jan Reedy
    Terry Reedy, Aug 8, 2010
    #3
  4. Tim Chase

    Peter Guest

    On Aug 9, 6:49 am, Terry Reedy <> wrote:
    > On 8/7/2010 7:53 AM, Peter Otten wrote:
    >
    >
    >
    > > You mean you'd go for the candidate who took the conservative approach and
    > > got it right:

    >
    > > print 1
    > > print 2
    > > print 'Fizz'
    > > print 4
    > > print 'Buzz'
    > > print 'Fizz'
    > > print 7
    > > print 8
    > > print 'Fizz'
    > > print 'Buzz'

    >
    > Way too verbose. How about
    > print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n
    > etc.
    >
    > --
    > Terry Jan Reedy


    And to hell with the code being maintainable afterwards? :)

    Personally I would FIRE somebody who produced code like this. Assuming
    I was a manager or in a position to hire (I used to be in a previous
    life), then I would be looking for somebody who was capable of writing
    good, solid and MAINTAINABLE code (love those subjective words? :)).

    Realistically, if the application is anything other than trivial then
    it will most likely have somebody poking around in it at some stage
    who isn't the brightest spark in the firmament. Anybody who produces
    nice, readable and straight forward code in my books gets the tick of
    approval.

    No offence intended, but anybody who tried to prove how "bright" they
    are by producing the least number of (unmaintainable) lines of code
    would not get past the first interview - unless they were prepared to
    sign a contract that guaranteed they would be available to maintain
    the application for its entire lifecycle. Generally (in my experience)
    people who write code like this don't hang around long - certainly not
    long enough to maintain their monstrosity!

    Peter
    Peter, Aug 9, 2010
    #4
  5. On Sun, 08 Aug 2010 17:28:59 -0700, Peter wrote:

    > On Aug 9, 6:49 am, Terry Reedy <> wrote:
    >> On 8/7/2010 7:53 AM, Peter Otten wrote:
    >>
    >> > You mean you'd go for the candidate who took the conservative
    >> > approach and got it right:

    >>
    >> > print 1
    >> > print 2
    >> > print 'Fizz'
    >> > print 4
    >> > print 'Buzz'
    >> > print 'Fizz'
    >> > print 7
    >> > print 8
    >> > print 'Fizz'
    >> > print 'Buzz'

    >>
    >> Way too verbose. How about
    >> print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n etc.
    >>
    >> --
    >> Terry Jan Reedy

    >
    > And to hell with the code being maintainable afterwards? :)



    I'm pretty sure both Peter Otten and Terry Reedy were being sarcastic and/
    or ironic.


    --
    Steven
    Steven D'Aprano, Aug 9, 2010
    #5
  6. Tim Chase

    Roy Smith Guest

    In article
    <>,
    Peter <> wrote:

    > Realistically, if the application is anything other than trivial then
    > it will most likely have somebody poking around in it at some stage
    > who isn't the brightest spark in the firmament. Anybody who produces
    > nice, readable and straight forward code in my books gets the tick of
    > approval.


    What he said.

    The first test of good code is that you can understand what you wrote
    six months after you wrote it.

    The second test is that you can explain it to some junior programmer a
    couple of cubes away from you, two or three years after you wrote it.

    The ultimate test is that some poor schmuck, long after you've moved on
    to another project (or company), can figure out what the heck you wrote,
    ten years later. And, oh, yeah, the junior programmer who you explained
    it to in the previous paragraph, may be 9 or 12 time zones away from the
    team who is currently maintaining your code, if he's around at all.
    Roy Smith, Aug 9, 2010
    #6
  7. Tim Chase

    Peter Guest

    On Aug 9, 10:39 am, Steven D'Aprano <st...@REMOVE-THIS-
    cybersource.com.au> wrote:
    > On Sun, 08 Aug 2010 17:28:59 -0700, Peter wrote:
    > > On Aug 9, 6:49 am, Terry Reedy <> wrote:
    > >> On 8/7/2010 7:53 AM, Peter Otten wrote:

    >
    > >> > You mean you'd go for the candidate who took the conservative
    > >> > approach and got it right:

    >
    > >> > print 1
    > >> > print 2
    > >> > print 'Fizz'
    > >> > print 4
    > >> > print 'Buzz'
    > >> > print 'Fizz'
    > >> > print 7
    > >> > print 8
    > >> > print 'Fizz'
    > >> > print 'Buzz'

    >
    > >> Way too verbose. How about
    > >> print("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n etc.

    >
    > >> --
    > >> Terry Jan Reedy

    >
    > > And to hell with the code being maintainable afterwards? :)

    >
    > I'm pretty sure both Peter Otten and Terry Reedy were being sarcastic and/
    > or ironic.
    >
    > --
    > Steven


    I'm sure you're right - and I repeat that I meant no offense.

    My comments were intended in the spirit of what to do or do not do in
    an interview for (any) programming job. Peter and Terry just offered
    some good examples of what you don't want to do (IMO) :)

    So, I apologise if anybody has taken my comments as a slur on Peter
    and/or Terry's posts - they were not intended as such.

    Peter
    Peter, Aug 9, 2010
    #7
  8. Tim Chase

    Terry Reedy Guest

    On 8/8/2010 10:16 PM, Peter wrote:

    >> I'm pretty sure both Peter Otten and Terry Reedy were being sarcastic and/
    >> or ironic.


    About the most I ever am ;=)!

    > I'm sure you're right - and I repeat that I meant no offense.
    >
    > My comments were intended in the spirit of what to do or do not do in
    > an interview for (any) programming job. Peter and Terry just offered
    > some good examples of what you don't want to do (IMO) :)
    >
    > So, I apologise if anybody has taken my comments as a slur on Peter
    > and/or Terry's posts - they were not intended as such.


    I was not sure if you were taking me seriously or not, but rather than
    be insulted, I am delighted that I gave you an opportunity to both get
    something off your chest and say something worthwhile.

    When I was hired in part to maintain and extend someone else's work, it
    was in pretty good shape and the outgoing person, with more experience
    than me, gave me a quick head's about about it. But I realize that many
    others have been less fortunate, but of course cannot throw a fit in
    their new place of employment, as appropriate as it might seem.

    --
    Terry Jan Reedy
    Terry Reedy, Aug 9, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Chase
    Replies:
    0
    Views:
    689
    Tim Chase
    Mar 4, 2009
  2. Steve Holden
    Replies:
    0
    Views:
    392
    Steve Holden
    Mar 4, 2009
  3. James Mills

    Re: python interview quuestions

    James Mills, Aug 6, 2010, in forum: Python
    Replies:
    12
    Views:
    489
    Simon Brunning
    Aug 13, 2010
  4. James Mills

    Re: python interview quuestions

    James Mills, Aug 6, 2010, in forum: Python
    Replies:
    3
    Views:
    247
    geremy condra
    Aug 7, 2010
  5. reema
    Replies:
    0
    Views:
    245
    reema
    Aug 26, 2008
Loading...

Share This Page