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.
Change to page (10 entries in each page): 1
© hover year to navigate month: powered by django