Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Last active December 30, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/7834117 to your computer and use it in GitHub Desktop.
Save damianesteban/7834117 to your computer and use it in GitHub Desktop.
# Write a program in Ruby that tells you how old I am
# if I am 979000000 seconds old. Display the result as a floating point (decimal) number to two
# decimal places (for example, 17.23). Note: To format the output to say 2 decimal
# places, we can use the Kernel's format method. For example, if x = 45.5678 then format("%.2f", x)
# will return the string 45.57
def seconds_to_years(seconds)
seconds_in_year = 31536000
age = seconds.to_f / seconds_in_year.to_f
printf "You are %.2f years old.", age
end
seconds_to_years(979000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment