Tim 說的 FizzBuzz 用一個迴圈就可以解決了:

import sys

for i in range(1,101):
    if i%15 == 0:
        sys.stdout.write( "FizzBuzz " )
    elif i%5 == 0:
        sys.stdout.write( "Buzz " )
    elif i%3 == 0:
        sys.stdout.write( "Fizz " )
    else:
        sys.stdout.write( "%d " % i )

當然遞迴也可以啦,離題也可以啦... 但對於「廁所程式」來說,這樣就夠了 :p

Posted by yungyuc at 09:30, 0 comment, 0 trackback.
Navigate
Add a trackback
Add a comment

Your name. (required)

Your personal website. (optional)

Your email address. Will not show in page. (suggested, but optional)

Text format is "Plain Text".

Enter "FcAgj"
© hover year to navigate month: powered by django