【发布时间】:2019-11-01 00:58:59
【问题描述】:
我正在尝试编写一个程序来打印 100 个数字的“fizz-buzz”列表。
Fizz-Buzz 是一款您尝试按顺序列出数字的游戏,但如果一个数字是 3 的倍数,您就说 fizz,如果一个数字是 5 的倍数,您就说 Buzz,如果两者都是,您就说“嘶嘶声”。
对于 10 个数字,它类似于 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz。
x = 1
while(x < 10):
if x % 3 == 0:
fizzint = True
elif x % 3 != 0:
fizzint = False
if x % 5 == 0:
buzzint = True
elif x % 5 != 0:
buzzint = False
if fizzint == True and buzzint == True:
print("FizzBuzz \n")
if fizzint == False and buzzint == False:
print(x)
print("\n")
if fizzint == True and buzzint == True:
print("Fizz \n")
if fizzint == True and buzzint == True:
print("Buzz \n")
x = x+1
问题在于程序会忽略所有 3 或 5 的倍数。
【问题讨论】:
标签: python python-3.x