twitcode.org
 
back FizzBuzz
Phyton
2011-10-10
pine613


FizzBuzz ネタが流れてきてたから、勉強中の Python で書いてみる。確かに、Python はコード綺麗だね。
Copy code copy code
  1. #!/usr/bin/python2.7
  2. # coding: utf-8
  3.  
  4. if __name__ == '__main__':
  5.     n = input()
  6.    
  7.     for i in range(1, n + 1):
  8.         if i % 3 > 0 and i % 5 > 0:
  9.             print i
  10.        
  11.         else:
  12.             if i % 3 == 0:
  13.                 print 'Fizz',
  14.            
  15.             if i % 5 == 0:
  16.                 print 'Buzz',
  17.            
  18.             print
  19.  
  20. # vim: se noet ts=4 sw=4 sts=0 ft=python :
  21.  


Recent comments: ( 0 )


Please loggin to leave a comment!!