Skip to content

Instantly share code, notes, and snippets.

@azhai
Created July 3, 2014 12:34
Show Gist options
  • Select an option

  • Save azhai/b3824d7677fb97c0d089 to your computer and use it in GitHub Desktop.

Select an option

Save azhai/b3824d7677fb97c0d089 to your computer and use it in GitHub Desktop.
FizzBuzz
# -*- coding: utf-8 -*-
# 运行环境:Python2.7 (Linux/Windows)
"""
题目给出的例子有错误,15——按题意规则5优先,
应该输出Buzz而不是FizzBuzz
好吧,我弄错,规则5只对第一个数字a起作用,那边更简单
"""
def count_hundred(a, b, c):
""" 100以内数字报数,5条规则参照https://www.jinshuju.net/f/EGQL3D """
assert 0 < a < 10 and 0 < b < 10 and 0 < c < 10
for i in xrange(1, 101):
print (str(a) in str(i) and 'Fizz') \
or (('' if i % a else 'Fizz') + ('' if i % b else 'Buzz') + ('' if i % c else 'Whizz')) \
or i
if __name__ == '__main__':
count_hundred(3, 5, 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment