Update temperature_conversions.rb

This commit is contained in:
Vitor Oliveira 2021-03-31 18:49:42 -07:00 committed by GitHub
parent 381b66bed3
commit 0607e30c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@
# celsius -> kelvin = value of celsius + 273.15 => K
def celsius_to_kelvin(celsius_input)
begin
kelvin_output = (celsius_input + 273.15).round(2);
kelvin_output = (celsius_input + 273.15).round(2)
rescue TypeError
puts "Error: Please provide number only!"
else
@ -14,8 +14,8 @@ end
# kelvin -> celsius = vale of kelvin - 273.15 => °C
def kelvin_to_celsius(kelvin_input)
begin
celsius_output = (kelvin_input - 273.15).round(2);
rescue
celsius_output = (kelvin_input - 273.15).round(2)
rescue TypeError
puts "Error: Please provide number only!"
else
puts "#{kelvin_input}K = #{celsius_output}°C"
@ -25,8 +25,8 @@ end
# celsius -> fahrenheit = (value of celsius * 9 / 5) + 32 => °F
def celsius_to_fahrenheit(celsius_input)
begin
fahrenheit_output = ((celsius_input * 9 / 5) + 32).round(2);
rescue
fahrenheit_output = ((celsius_input * 9 / 5) + 32).round(2)
rescue TypeError
puts "Error: Please provide number only!"
else
puts "#{celsius_input}°C = #{fahrenheit_output}°F"
@ -36,8 +36,8 @@ end
# fahrenheit -> celsius = (value of fahrenheit - 32) * 5 / 9 => °C
def fahrenheit_to_celsius(fahrenheit_input)
begin
celsius_output = ((fahrenheit_input - 32) * 5 / 9).round(2);
rescue
celsius_output = ((fahrenheit_input - 32) * 5 / 9).round(2)
rescue TypeError
puts "Error: Please provide number only!"
else
puts "#{fahrenheit_input}°F = #{celsius_output}°C"
@ -48,7 +48,7 @@ end
def fahrenheit_to_kelvin(fahrenheit_input)
begin
kelvin_output = ((fahrenheit_input - 32) * 5 / 9).round(2).round(2)
rescue
rescue TypeError
puts "Error: Please provide number only!"
else
puts "#{fahrenheit_input}°F = #{kelvin_output}K"
@ -58,8 +58,8 @@ end
# kelvin -> fahrenheit = [(value of kelvin - 32) * 5 / 9] + 273.15 => K
def kelvin_to_fahrenheit(kelvin_input)
begin
fahrenheit_output = (((kelvin_input - 273.15) * 9 / 5) + 32).round(2).round(2);
rescue
fahrenheit_output = (((kelvin_input - 273.15) * 9 / 5) + 32).round(2).round(2)
rescue TypeError
puts "Error: Please provide number only!"
else
puts "#{kelvin_input}K = #{fahrenheit_output}°F"