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
- Previous: Fantastic Python one-liner @2007/03/06
- Next: customize docutils @2007/03/14
Add a trackback
Please send trackback to: http://blog.seety.org/everydaywork/2007/3/10/657/trackback/.
Add a comment