Study Drills:
1. Above each line, use the # to write a comment to yourself explaining what the line does.

2. Remember in Exercise 0 when you started Ruby? Start Ruby this way again and using the math operators, use Ruby as a calculator.

I typed irb in Terminal to start interactive Ruby. Here are some math calculations I did. I played around with floating point numbers and integers. I also used the comparison operators, less than and greater than, to compare results of math calculations.

3. Notice the math seems “wrong”? There are no fractions, only whole numbers. You need to use a “floating point” number, which is a number with a decimal point, as in 10.5, or 0.89, or even 3.0. Yes, the math seems “wrong” because 3 / 2 is 1 in Ruby. However, 3.0 / 2 is 1.5!

4. Rewrite ex3.rb to use floating point numbers so it’s more accurate. 20.0 is floating point.

For Study Drill #4, I changed one integer in each calculation into a float. I could do this because mathematical calculations with float objects and others return float objects. From the Ruby documentation, we see that a float object added to other returns a new float object. The same goes for subtraction, division, multiplication, modulo operation. By changing one of our integers into a float (For example on line 23, 3 + 2 is changed into 3.0 + 2), we get as the result 5.0 which is a float object.