When you divide any integer number by the '/' operator you always have the type float, even when division is an int. Test for yourself: type(2/2)
returns float.
To check wheter N can be divided by M, it's usually better to test modulo N%M==0
.
You can try this:
def fizz_buzz(n):
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
print('FizzBuzz')
elif i % 3 == 0:
print('Fizz')
elif i % 5 == 0:
print('Buzz')
else:
print(i)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…