Skip to content

Instantly share code, notes, and snippets.

@johnta0
Created July 8, 2017 09:13
Show Gist options
  • Save johnta0/e8975efbfc2eb0a4cbe81aa75c7627bc to your computer and use it in GitHub Desktop.
Save johnta0/e8975efbfc2eb0a4cbe81aa75c7627bc to your computer and use it in GitHub Desktop.
剰余演算子を使わないFizzBuzzプログラム(1)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
## 剰余演算子を使わないFizzBuzzプログラム(1)
## 注)このプログラムはPython2系においてのみ正常に動作する
def fizzbuzz():
for i in range(1,100):
# 割り切れない場合は小数型になってしまうことを利用した。(Python2では動作するがPython3では整数型と小数型を比較できるようになっているので成城に動作しない)
if ( i / 15 ) * 15 == i :print "FizzBuzz"
elif ( i / 5 ) * 5 == i :print "Buzz"
elif ( i / 3 ) * 3 == i :print "Fizz"
else :print i
if __name__ == '__main__':
fizzbuzz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment