Ruby_work basic problem

Model answer

work.rb




#####Problem 1 (review of four arithmetic operations and if statements)#####
#Please write the code after the if statement below to ensure correct display.

number = 5

if number % 2 == 0
  puts "Is an even number"
else
  puts "Is odd"
end

#####Problem 2 (review of formula expansion)#####
#Please write the code so that the following is displayed

name = "Yamada" 

#Please describe so that "I am ●●" is displayed.

puts "I#{name}is"

#####Problem 3 (review of array)#####
#Please write the code for ① to ④ below

# ①"Tanaka","Sato","Yamada"Define an array called students with three names.
students = ["Tanaka", "Sato", "Yamada"]

#② In the array created in ①"Suzuki"Please add.
students << "Suzuki"

#③ Output the array created in ② to the terminal.
puts students

#④ Specify the number from the array"Sato"Please take out and output to the terminal
puts students[1]

#####Problem 4 (review of hash)#####
#Please write the code for ① to ③ below

#① From the hash called sasaki below"Tokyo"Please take out and output to the terminal
sasaki = {from: "Tokyo", age: 30}

puts sasaki[:from]

#② job to hash called sasaki:With the key"teacher"Please add the value
sasaki[:job] = "teacher"

#③ Output the value of the key called job added in ② to the terminal.
puts sasaki[:job]


Recommended Posts

Ruby_work basic problem
[N + 1 problem]
Basic type-java
Basic knowledge
FizzBuzz problem
Ruby problem ⑦