提示文字
使用 Python 寫入 Fizzbuzz。為每一行加註。
回應範例
沒問題,以下是以 Python 撰寫的 FizzBuzz 程式,並加入評論:
# This program prints the numbers from 1 to 100.
# For multiples of three, it prints "Fizz" instead of the number.
# For multiples of five, it prints "Buzz" instead of the number.
# For numbers which are multiples of both three and five, it prints "FizzBuzz" instead of the number.
for i in range(1, 101):
# Check if i is divisible by 3.
if i % 3 == 0:
# If i is divisible by 3, print "Fizz".
print("Fizz")
# Check if i is divisible by 5.
elif i % 5 == 0:
# If i is divisible by 5, print "Buzz".
print("Buzz")
# If i is not divisible by 3 or 5, print i.
else:
print(i)
希望以上資訊對你有幫助!如有其他問題,歡迎與我們聯絡。