Run your Ruby file by typing ruby
and then the name of the file you want to run in the Terminal.
If we want to run float_round.rb
, we can write the command:
ruby float_round.rb
To re-run this command, you can use the UP and DOWN arrow keys to look at the history of commands you've run in a Terminal.
A right triangle's two shorter sides have length 2.8
and 4.5
. Write a program to calculate how long its longest side is and print it.
Remember: the Pythagorean Theorem says that
where a
and b
are the lengths of the shorter sides, and c
is the length of the longest side.
Your program should output a number; for example,
5.3
Read more about the formula: https://www.mathsisfun.com/pythagoras.html
Write a program that calculates 10 divided by 3 and rounds the result to 3 decimal places. The program should print this result.
3.333
Click here to see names of each test
float_find_hypotenuse.rb should output '5.3''
float_round.rb should output '3.333'