LoginSignup
0
0

robloxでassistant その6

Posted at

概要

robloxでassistantやってみた。

質問

fizzbuzzを教えて

回答

FizzBuzzは、プログラミングの面接試験や練習問題でよく使われる問題です。以下はFizzBuzzの解法の一つです。

1から100までの数を順番に出力しますが、3で割り切れる場合は"Fizz"、5で割り切れる場合は"Buzz"、3と5で割り切れる場合は"FizzBuzz"と表示します。それ以外の場合は、その数を表示します。

以下はLuaでFizzBuzzを実装する例です。

for i = 1, 100 do
	if i % 3 == 0 and i % 5 == 0 then
		print("FizzBuzz")
	elseif i % 3 == 0 then
		print("Fizz")
	elseif i % 5 == 0 then
		print("Buzz")
	else
		print(i)
	end
end

このコードをRoblox Studioのスクリプトに追加して実行すると、1から100までのFizzBuzzが出力されます。

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0