coding Ruby 1. The following codeblock has an error in it. Fix it so it prints \
ID: 3712047 • Letter: C
Question
coding Ruby
1. The following codeblock has an error in it. Fix it so it prints "The answer to the ultimate question of life, the universe, and everything is 42" on the screen.
puts 'i'm using Ruby!'"
2. The following codeblock has an error in it. Fix it so it prints "The answer to the ultimate question of life, the universe, and everything is 42" on the screen.
answer = 42
puts "The answer to the ultimate question of life, the universe, and everything is " + "answer"
3.Keeping in mind there are 86400 seconds in a day, write a program that calculates how many seconds there are in a week, if a week is 7 days. Print the result on the screen.
4.What does the Ruby expression 7 * 10 + 2 evaluate to?
5.What does the Ruby expression "Hello" + "World!" evaluate to?
6.What does the Ruby expression 10 % 10 evaluate to?
7.What does the Ruby expression (2**2) == 4 evaluate to?
8.Keeping in mind order of precedence, what does the following expression evaluate to? 1 < 2 || 5 > 4 && 7 <= 7
9.What does the boolean expression !false && true evaluate to?
Explanation / Answer
1) It can be simply printed using the puts statement as follows:
puts ""The answer to the ultimate question of life, the universe, and everything is 42"";
use the escape sequence to print the ' symbol as follows:
puts "'i'm using Ruby!'";
2)
answer = 42
puts "The answer to the ultimate question of life, the universe, and everything is #{answer}";
3)
day_sec = 86400;
#multiply to get total no of seconds in the week
week_sec = 7*day_sec;
puts "total number of seconds in the week is #{week_sec}";
4)
It evaluates &2 ait multiply 7 with 10 and then add 2 to it
5)
it evaluates it as
HelloWorld! as it simply concatenate the strings
6)
0 is the evaluated answer as % is for the remainder and 10%10 gives remainder as 0
7)
the answer to this is true
8)
it evaluates it to true going in order of preference of the operators
9)
answer is true as ! false is true
and true && true is again true
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.