Getting started with python

Steve Holden steve at holdenweb.com
Sun Apr 15 20:48:41 EDT 2007


James Stroud wrote:
> Gabriel Genellina wrote:
>> En Sun, 15 Apr 2007 10:46:54 -0300, Army1987 <please.ask at for.it> escribió:
>>
>>> "Paddy" <paddy3118 at googlemail.com> ha scritto nel messaggio
>>> news:1176608302.928513.274400 at y5g2000hsa.googlegroups.com...
>>>
>>>> On a different tack, from:
>>>> http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/ 
>>>>
>>>> It seems you need to learn how to write a Fizz-Buzz
>>>> program to get a job now-a-days :-)
>>> Something less idiotic? I took longer to type a program to do that 
>>> than to
>>> figure out how to do that.
>> We've used it as part of a test a few weeks ago. You'd be surprised on 
>> how many guys couldn't write anything remotely sensible.
>>
>> --Gabriel Genellina
> 
> py> for i in xrange(1,101):
> ...   if not i % 15:
> ...     print 'fizzbuzz'
> ...     continue
> ...   if not i % 5:
> ...     print 'buzz'
> ...     continue
> ...   if not i % 3:
> ...     print 'fizz'
> ...   else:
> ...     print i
> ...
> 
> I typed this without so much as hitting delete. Didn't time it but I'm 
> guessing less than 2 minutes. How much am I worth a year? (Hopefully 
> capitalization is not important for this exercise.)
> 
You'd be worth more if you'd used elif and omitted the continue 
statements, but for a first solution it's acceptable.

For better readability I'd have used

     if i % 5 == 0

rather than

     if not i % 5

but that's mostly a stylistic matter.

regards
  Steve
regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com



More information about the Python-list mailing list