0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Paiza問題集】条件分岐/FizzBuzz

Posted at

Paiza問題集

Pythonで回答

条件分岐/FizzBuzz

Step01 3の倍数判定

"""
3の倍数判定
https://paiza.jp/works/mondai/conditions_branch/conditions_branch__mod_step1

問題
整数Nが与えられます
Nが3の倍数の場合はYESを、そうではない場合はNOを出力してください
"""

print("YES" if int(input())%3==0 else "NO")

Step02 2つの倍数判定

"""
2つの倍数判定
https://paiza.jp/works/mondai/conditions_branch/conditions_branch__mod_step2

問題
2つの倍数判定
整数Nが与えられます
Nが3の倍数かつ5の倍数の場合はYESを、そうではない場合はNOを出力してください
"""

N = int(input())
print("YES" if N%3==0 and N%5==0 else "NO")

Step03 偶奇の判定

"""
偶奇の判定
https://paiza.jp/works/mondai/conditions_branch/conditions_branch__mod_step3

問題
長さNの数列Aが与えられます
この数列に含まれる偶数の要素の個数と、奇数の要素の個数を答えてください
"""

N = int(input())
A = map(int, (input().split()))
even, odd = 0, 0

for i in A:
    if i % 2 == 0:
        even += 1
    else:
        odd += 1

print(f"{even} {odd}")

Step04 曜日の判定

"""
曜日の判定
https://paiza.jp/works/mondai/conditions_branch/conditions_branch__mod_step4

問題
ある月の1日は日曜日、2日は月曜日...です
X日は何曜日でしょう
"""

X = int(input())
week = ["Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"]

print(week[X % 7])

Final問題 FizzBuzz

"""
FizzBuzz
https://paiza.jp/works/mondai/conditions_branch/conditions_branch__mod_boss

問題
整数Nが与えられます
Nが3で割り切れる場合はFizz、Nが5で割り切れる場合はBuzz、 Nが3と5の両方で割り切れる場合はFizzやBuzzの代わりにFizzBuzzを出力してください
ただし、Nが3の倍数でも5の倍数でもないときはNをそのまま出力してください。
"""

N = int(input())

if N % 15 == 0:
    print("FizzBuzz")
elif N % 3 == 0:
    print("Fizz")
elif N % 5 == 0:
    print("Buzz")
else:
    print(N)
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?