This post is Private. Only a writer or those who know its URL can access this post.

Improve article
RevisionsShow article in Markdown
Report article
Help us understand the problem. What is going on with this article?

# Rubyでやるプログラミングのドリル

More than 1 year has passed since last update.

```a = 1
b = 2
c = a + b
c = c + 1

puts c
```

```a = 8
b = 2
c = a - b
puts c

c = c / b
puts c
```

```a = 6
b = 2
c = a * b
puts c

c = c + 1
puts c
```

```a = 6
b = 2
c = a * b
puts c

c = c / a
puts c
```

```a = 6
b = 2
c = a * b
puts c

c = c / (a - b)
puts c
```

```age = 0
price = 0

if age == 0
price = 100
else
price = 500
end

puts price
```

```age = 5
price = 0

if age == 0
price = 100
else
price = 500
end

puts price
```

```age = 5
price = 0

if age == 0
price = 100
end

puts price

```

```age = 1
price = 0

if age == 0
price = 100
elsif age == 1
price = 300
else
price = 500
end

puts price
```

```age = 0
price = 0

if age > 0
price = 100
else
price = 500
end

puts price
```

```age = 0
price = 0

if age >= 0
price = 100
else
price = 500
end

puts price
```

```age = 0
price = 0

if age < 1
price = 100
else
price = 500
end

puts price
```

```age = 2
price = 0

if age <= 1
price = 100
else
price = 500
end

puts price
```

```age = 2
birth = 2000
price = 0

if age == 2 && birth == 2001
price = 100
else
price = 500
end

puts price
```

```age = 2
birth = 2000
price = 0

if age == 2 || birth == 2001
price = 100
else
price = 500
end

puts price
```

```age = 2
birth = 2000
price = 0

if age == 2 && birth == 2000
price = 100
else
price = 500
end

puts price
```

```age = 2
birth = 2000
price = 0

if age == 2 || birth == 2000
price = 100
else
price = 500
end

puts price
```

```age = 2
birth = 2000
price = 0

if age == 2
if birth == 2001
price = 100
else
price = 300
end
else
price = 500
end

puts price
```

```money = 1000
money = money * 1.1
money = money * 1.1
money = money * 1.1

puts money.to_i
```

```money = 1000
1.upto(3) do
money = money * 1.1
end
puts money.to_i
```

```money = 1000
rate = 1.1
1.upto(4) do
money = money * rate
end
puts money.to_i
```

```money = 1000
rate = 1.1
2001.upto(2004) do
money = money * rate
end
puts money.to_i
```

```money = 1000
rate = 1.1
(2001..2010).step(2) do
money = money * rate
end
puts money.to_i
```

```money = 1000
rate = 1.1
(2001..2010).step(3) do
money = money * rate
end
puts money.to_i
```

```money = 1000
(1..10).each do
(1..10).each do
money = money + 1
end
end

puts money
```

```val = "cebu"
puts "Hello #{val} welcome"

```

```val = 1
puts "Hello #{1 * 10} welcome"
```

```money = 1000
rate = 1.1
2001.upto(2004) do |i|
money = money * rate
puts "I got #{money.to_i} in #{i}."
end
```

```(1..10).each do |i|
(1..10).each do |v|
puts "i = #{i}"
puts "v = #{v}"
end
end
```

```(1..10).each do |i|
(1..10).each do |v|
puts "i = #{i}" if i % 2 == 0
puts "v = #{v}" if v % 2 == 1
end
end
```

```def print_hello(v)
puts "hello, #{v}"
end

(1..10).each do |i|
print_hello(i)
end
```

```a = 0
b = 0

(1..10).each do
if a > b
b = b + 1
puts "1; a = #{a}, b = #{b}"
else
a = a + 1
puts "2; a = #{a}, b = #{b}"
end
end
```

```def display_price(price)
case price
when 100 then
size = "small"
when 200 then
size = "mid"
when 300 then
size = "large"
else
size = "LL"
end

print "size is #{size}"
end

display_price(100)
display_price(200)
display_price(300)
display_price(400)
```

```def display_price(price)
size = case price
when 100 then
"small"
when 200 then
"mid"
when 300 then
"large"
else
"LL"
end

print "size is #{size}"
end

display_price(100)
display_price(200)
display_price(300)
display_price(400)
```

```def cal_bmi(height, weight)
if height > 180
bmi = weight / (height * 0.01) ** 2
puts "You are tall. This is your #{bmi}"
elsif weight > 80
bmi = weight / (height * 0.01) ** 2
puts "You are big. This is your #{bmi}"
elsif height < 160 && weight < 50
bmi = weight / (height * 0.01) ** 2
puts "You are small. This is your #{bmi}"
else
bmi = weight / (height * 0.01) ** 2
puts "You are normal. This is your #{bmi}"
end
end

cal_bmi(187, 65)
cal_bmi(180, 90)
cal_bmi(159, 49)
cal_bmi(159, 60)
```

```def cal_bmi(height, weight)
bmi = weight / (height * 0.01) ** 2
message =
if height > 180
"You are tall. This is your #{bmi}"
elsif weight > 80
"You are big. This is your #{bmi}"
elsif height < 160 && weight < 50
"You are small. This is your #{bmi}"
else
"You are normal. This is your #{bmi}"
end
puts message
end

cal_bmi(187, 65)
cal_bmi(180, 90)
cal_bmi(159, 49)
cal_bmi(159, 60)
```

```def cal_bmi(height, weight)
bmi = weight / (height * 0.01) ** 2
message =
if height > 180
"tall"
elsif weight > 80
"big"
elsif height < 160 && weight < 50
"small"
else
"normal"
end
puts "You are #{message}. This is your #{bmi}"
end

cal_bmi(187, 65)
cal_bmi(180, 90)
cal_bmi(159, 49)
cal_bmi(159, 60)
```
I worked in Philippines and work in Tokyo.
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away