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 3 years have passed since last update.

if,else問題

Posted at

#21時から翌朝6時までにオウムに喋られると問題があるのでその場合は「NG」、それ以外は「OK」と出力するメソッドを作成します。オウムが喋る時をtrue、喋らない時をfalseと入力することにし、時刻も同時に入力します。

答えと解釈

def parrot_trouble(talking, hour)
  if talking && (hour < 6 || hour >= 21)
    puts "NG"
  else
    puts "OK"
  end
end

これは呼び出し方です

parrot_trouble(talking, hour)

日本語訳するとしたらこんな感じ
オウムがtalkingするのはNGです。(6時-21時の間は)
それ以外の場合はOK

&&と||の使い方
「A && B」で「AかつB」
「A || B」で「AまたはB」

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?