Quantcast
Channel: 初心者タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 22058

【ruby】『ruby入門(メモ6)』メソッドで恐竜fizzbuzzを作ってみよう(windows10+ruby2.3.3)

$
0
0

0.あると望ましい(どうでもいい)前提知識

超久しぶりの投稿!
気分転換のためにfizzbuzzを作成してみました。
インドミナスレックス(IndominusRex):ヴェロキラプトルとティラノザウルスを融合させた恐竜。
インドラプトル(Indoraptor):インドミナスレックスとヴェロキラプトルを融合させた恐竜。

この知識を前提に変形fizzbuzzを作ってみた。
最後にインドラプトルが表示されていれば成功!

1.コード

method_fizzbuzz.rb
defact_dino(dinosor)ifdinosor=='Tyrannosaurus'puts'Bite!!'elsifdinosor=='Stegosaurus'puts'Waving the tail!'elseputs'???'endenddefFizzBuzz_dinosor(n)#インドラプトルifn%45==0'Indoraptor'#インドミナスレックス elsifn%15==0'IndominusRex'#ティラノサウルスelsifn%5==0'Tyrannosaurus'#ヴェロキラプトル   elsifn%3==0'Velociraptor'elsen.to_sendendact_dino("tiger")act_dino("Stegosaurus")n=0whilen<45don+=1putsFizzBuzz_dinosor(n)end

2.実行結果

c:\ruby_pg>ruby method_fizzbuzz.rb
???
Waving the tail!
1
2
Velociraptor
4
Tyrannosaurus
Velociraptor
7
8
Velociraptor
Tyrannosaurus
11
Velociraptor
13
14
IndominusRex
16
17
Velociraptor
19
Tyrannosaurus
Velociraptor
22
23
Velociraptor
Tyrannosaurus
26
Velociraptor
28
29
IndominusRex
31
32
Velociraptor
34
Tyrannosaurus
Velociraptor
37
38
Velociraptor
Tyrannosaurus
41
Velociraptor
43
44
Indoraptor

c:\ruby_pg>

Viewing all articles
Browse latest Browse all 22058

Trending Articles