Решение на Първа задача - температура и химични елементи от Добрин Цветков

Обратно към всички решения

Към профила на Добрин Цветков

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 17 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def convert_to_celsius(degrees, from_units)
if from_units == 'C'
degrees
elsif from_units == 'K'
degrees - 273.15
elsif from_units == 'F'
(degrees - 32) * 5 / 9
end
end
def convert_from_celsius(degrees, to_units)
if to_units == 'C'
degrees
elsif to_units == 'K'
degrees + 273.15
elsif to_units == 'F'
degrees * 1.8 + 32
end
end
def convert_between_temperature_units(degrees, from_units, to_units)
if to_units == from_units
degrees
else
degrees_in_celsius = convert_to_celsius(degrees, from_units)
convert_from_celsius(degrees_in_celsius, to_units)
end
end
MELTING_POINTS = {
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
def melting_point_of_substance(substance, in_which_temperature_unit)
if MELTING_POINTS[substance]
if in_which_temperature_unit == 'C'
MELTING_POINTS[substance]
elsif in_which_temperature_unit == 'K'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'K')
elsif in_which_temperature_unit == 'F'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'F')
end
end
end
BOILING_POINTS = {
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
def boiling_point_of_substance(substance, in_which_temperature_unit)
if BOILING_POINTS[substance]
if in_which_temperature_unit == 'C'
BOILING_POINTS[substance]
elsif in_which_temperature_unit == 'K'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'K')
elsif in_which_temperature_unit == 'F'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'F')
end
end
end

Лог от изпълнението

.................

Finished in 0.00797 seconds
17 examples, 0 failures

История (8 версии и 9 коментара)

Добрин обнови решението на 12.10.2016 17:42 (преди над 7 години)

+def convert_between_temperature_units(degrees, current_unit, wanted_unit)
+
+ if current_unit == "C"
+ if wanted_unit == "F"
+ degrees * 1.8 + 32
+ elsif wanted_unit == "K"
+ degrees + 273.15
+ elsif wanted_unit == "C"
+ degrees
+ else
+ "Invalid input"
+ end
+ elsif current_unit == "K"
+ if wanted_unit == "C"
+ degrees - 273.15
+ elsif wanted_unit == "F"
+ degrees * 9 / 5 - 459.67
+ elsif wanted_unit == "K"
+ degrees
+ else
+ "Invalid input"
+ end
+ elsif current_unit == "F"
+ if wanted_unit == "C"
+ (degrees - 32) * 5 / 9
+ elsif wanted_unit == "K"
+ (degrees + 459.67) * 5 / 9
+ elsif wanted_unit == "F"
+ degrees
+ else
+ "Invalid input"
+ end
+ end
+
+end
+
+def melting_point_of_substance(substance, wanted_temperature_unit)
+ temprerature_celsius =
+ if substance == "water"
+ 0
+ elsif substance == "ethanol"
+ -114
+ elsif substance == "gold"
+ 1_064
+ elsif substance == "silver"
+ 961.8
+ elsif substance == "copper"
+ 1_085
+ end
+
+ if wanted_temperature_unit == "C"
+ temprerature_celsius
+ elsif wanted_temperature_unit == "K"
+ convert_between_temperature_units(temprerature_celsius, "C", "K")
+ elsif wanted_temperature_unit == "F"
+ convert_between_temperature_units(temprerature_celsius, "C", "F")
+ end
+end
+
+def boiling_point_of_substance(substance, wanted_temperature_unit)
+ temprerature_celsius =
+ if substance == "water"
+ 100
+ elsif substance == "ethanol"
+ 78.37
+ elsif substance == "gold"
+ 2_700
+ elsif substance == "silver"
+ 2_162
+ elsif substance == "copper"
+ 2_567
+ end
+
+ if wanted_temperature_unit == "C"
+ temprerature_celsius
+ elsif wanted_temperature_unit == "K"
+ convert_between_temperature_units(temprerature_celsius, "C", "K")
+ elsif wanted_temperature_unit == "F"
+ convert_between_temperature_units(temprerature_celsius, "C", "F")
+ end
+
+end

Добрин обнови решението на 13.10.2016 15:24 (преди над 7 години)

def convert_between_temperature_units(degrees, current_unit, wanted_unit)
- if current_unit == "C"
- if wanted_unit == "F"
+ if current_unit == 'C'
+ if wanted_unit == 'F'
degrees * 1.8 + 32
- elsif wanted_unit == "K"
+ elsif wanted_unit == 'K'
degrees + 273.15
- elsif wanted_unit == "C"
+ elsif wanted_unit == 'C'
degrees
else
- "Invalid input"
+ 'Invalid input'
end
- elsif current_unit == "K"
- if wanted_unit == "C"
+ elsif current_unit == 'K'
+ if wanted_unit == 'C'
degrees - 273.15
- elsif wanted_unit == "F"
+ elsif wanted_unit == 'F'
degrees * 9 / 5 - 459.67
- elsif wanted_unit == "K"
+ elsif wanted_unit == 'K'
degrees
else
- "Invalid input"
+ 'Invalid input'
end
- elsif current_unit == "F"
- if wanted_unit == "C"
+ elsif current_unit == 'F'
+ if wanted_unit == 'C'
(degrees - 32) * 5 / 9
- elsif wanted_unit == "K"
+ elsif wanted_unit == 'K'
(degrees + 459.67) * 5 / 9
- elsif wanted_unit == "F"
+ elsif wanted_unit == 'F'
degrees
else
- "Invalid input"
+ 'Invalid input'
end
end
end
def melting_point_of_substance(substance, wanted_temperature_unit)
- temprerature_celsius =
- if substance == "water"
- 0
- elsif substance == "ethanol"
- -114
- elsif substance == "gold"
- 1_064
- elsif substance == "silver"
- 961.8
- elsif substance == "copper"
- 1_085
- end
+ melting_points =
+ {
+ 'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
+ 'silver' => 961.8, 'copper' => 1_085
+ }
- if wanted_temperature_unit == "C"
- temprerature_celsius
- elsif wanted_temperature_unit == "K"
- convert_between_temperature_units(temprerature_celsius, "C", "K")
- elsif wanted_temperature_unit == "F"
- convert_between_temperature_units(temprerature_celsius, "C", "F")
+ if melting_points[substance]
+ if wanted_temperature_unit == 'C'
+ melting_points[substance]
+ elsif wanted_temperature_unit == 'K'
+ convert_between_temperature_units(melting_points[substance], 'C', 'K')
+ elsif wanted_temperature_unit == 'F'
+ convert_between_temperature_units(melting_points[substance], 'C', 'F')
+ end
+ else
+ 'Invalid input'
end
end
def boiling_point_of_substance(substance, wanted_temperature_unit)
- temprerature_celsius =
- if substance == "water"
- 100
- elsif substance == "ethanol"
- 78.37
- elsif substance == "gold"
- 2_700
- elsif substance == "silver"
- 2_162
- elsif substance == "copper"
- 2_567
- end
+ boiling_points =
+ {
+ 'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
+ 'silver' => 2_162, 'copper' => 2_567
+ }
- if wanted_temperature_unit == "C"
- temprerature_celsius
- elsif wanted_temperature_unit == "K"
- convert_between_temperature_units(temprerature_celsius, "C", "K")
- elsif wanted_temperature_unit == "F"
- convert_between_temperature_units(temprerature_celsius, "C", "F")
+ if boiling_points[substance]
+ if wanted_temperature_unit == 'C'
+ boiling_points[substance]
+ elsif wanted_temperature_unit == 'K'
+ convert_between_temperature_units(boiling_points[substance], 'C', 'K')
+ elsif wanted_temperature_unit == 'F'
+ convert_between_temperature_units(boiling_points[substance], 'C', 'F')
+ end
+ else
+ 'Invalid input'
end
-
end

Добрин обнови решението на 13.10.2016 17:09 (преди над 7 години)

-def convert_between_temperature_units(degrees, current_unit, wanted_unit)
+def convert_between_temperature_units(
+ degrees, current_unit, wanted_unit
+)
if current_unit == 'C'
if wanted_unit == 'F'
degrees * 1.8 + 32
elsif wanted_unit == 'K'
degrees + 273.15
elsif wanted_unit == 'C'
degrees
else
'Invalid input'
end
elsif current_unit == 'K'
if wanted_unit == 'C'
degrees - 273.15
elsif wanted_unit == 'F'
degrees * 9 / 5 - 459.67
elsif wanted_unit == 'K'
degrees
else
'Invalid input'
end
elsif current_unit == 'F'
if wanted_unit == 'C'
(degrees - 32) * 5 / 9
elsif wanted_unit == 'K'
(degrees + 459.67) * 5 / 9
elsif wanted_unit == 'F'
degrees
else
'Invalid input'
end
end
end
def melting_point_of_substance(substance, wanted_temperature_unit)
melting_points =
{
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
- if melting_points[substance]
+ if melting_points[substance] && substance != nil
if wanted_temperature_unit == 'C'
melting_points[substance]
elsif wanted_temperature_unit == 'K'
- convert_between_temperature_units(melting_points[substance], 'C', 'K')
+ convert_between_temperature_units(
+ melting_points[substance], 'C', 'K'
+ )
elsif wanted_temperature_unit == 'F'
- convert_between_temperature_units(melting_points[substance], 'C', 'F')
+ convert_between_temperature_units(
+ melting_points[substance], 'C', 'F'
+ )
end
else
'Invalid input'
end
end
def boiling_point_of_substance(substance, wanted_temperature_unit)
boiling_points =
{
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
- if boiling_points[substance]
+ if boiling_points[substance] && substance != nil
if wanted_temperature_unit == 'C'
boiling_points[substance]
elsif wanted_temperature_unit == 'K'
- convert_between_temperature_units(boiling_points[substance], 'C', 'K')
+ convert_between_temperature_units(
+ boiling_points[substance], 'C', 'K'
+ )
elsif wanted_temperature_unit == 'F'
- convert_between_temperature_units(boiling_points[substance], 'C', 'F')
+ convert_between_temperature_units(
+ boiling_points[substance], 'C', 'F'
+ )
end
else
'Invalid input'
end
end

Добрин обнови решението на 13.10.2016 17:16 (преди над 7 години)

def convert_between_temperature_units(
degrees, current_unit, wanted_unit

wanted_unit :/ Колко пари е наградата ако го намеря? Какво ще кажеш за from_units и to_units?

Също, това подреждане на аргументите е в разрез със стиловите правила - сложи ги на един ред със скобите.

)
if current_unit == 'C'
if wanted_unit == 'F'
degrees * 1.8 + 32
elsif wanted_unit == 'K'
degrees + 273.15
elsif wanted_unit == 'C'
degrees
else
'Invalid input'

Не се грижи за невалидни аргументи. Просто изпусни else-а. В условието пише, че няма да ви даваме невалидни данни. Освен това, да върнеш произволен стринг е лошо поведение в такъв случай. Просто го остави да гръмне или да върне nil.

end
elsif current_unit == 'K'
if wanted_unit == 'C'
degrees - 273.15
elsif wanted_unit == 'F'
degrees * 9 / 5 - 459.67
elsif wanted_unit == 'K'
degrees
else
'Invalid input'
end
elsif current_unit == 'F'
if wanted_unit == 'C'
(degrees - 32) * 5 / 9
elsif wanted_unit == 'K'
(degrees + 459.67) * 5 / 9
elsif wanted_unit == 'F'

Идеята ми е помощна функция convert_to_celsius, която винаги да се извиква в началото на convert_between_temperature_units и след това помощна функция convert_from_celsius. Или с 3 помощни функции convert_to_celsius, convert_to_fahrenheit и convert_to_kelvin. Заемам се веднага и след малко качвам нов вариант. Благодаря за забележките :)

degrees
else
'Invalid input'
end
end
end
def melting_point_of_substance(substance, wanted_temperature_unit)
melting_points =
{
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
- if melting_points[substance] && substance != nil
+ if melting_points[substance]
if wanted_temperature_unit == 'C'
melting_points[substance]
elsif wanted_temperature_unit == 'K'
convert_between_temperature_units(
melting_points[substance], 'C', 'K'
)
elsif wanted_temperature_unit == 'F'
convert_between_temperature_units(
melting_points[substance], 'C', 'F'
)
end
else
'Invalid input'
end
end
def boiling_point_of_substance(substance, wanted_temperature_unit)
boiling_points =
{
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
- if boiling_points[substance] && substance != nil
+ if boiling_points[substance]
if wanted_temperature_unit == 'C'
boiling_points[substance]
elsif wanted_temperature_unit == 'K'
convert_between_temperature_units(
boiling_points[substance], 'C', 'K'
)
elsif wanted_temperature_unit == 'F'
convert_between_temperature_units(
boiling_points[substance], 'C', 'F'
)
end
else
'Invalid input'
end
end

Добрин обнови решението на 14.10.2016 13:32 (преди над 7 години)

-def convert_between_temperature_units(
- degrees, current_unit, wanted_unit
-)
+def convert_to_celsius(degrees, from_units)
+ if from_units == 'C'
+ degrees
+ elsif from_units == 'K'
+ degrees - 273.15
+ elsif from_units == 'F'
+ (degrees - 32) * 5 / 9
+ end
+end
- if current_unit == 'C'
- if wanted_unit == 'F'
- degrees * 1.8 + 32
- elsif wanted_unit == 'K'
- degrees + 273.15
- elsif wanted_unit == 'C'
- degrees
- else
- 'Invalid input'
- end
- elsif current_unit == 'K'
- if wanted_unit == 'C'
- degrees - 273.15
- elsif wanted_unit == 'F'
- degrees * 9 / 5 - 459.67
- elsif wanted_unit == 'K'
- degrees
- else
- 'Invalid input'
- end
- elsif current_unit == 'F'
- if wanted_unit == 'C'
- (degrees - 32) * 5 / 9
- elsif wanted_unit == 'K'
- (degrees + 459.67) * 5 / 9
- elsif wanted_unit == 'F'
- degrees
- else
- 'Invalid input'
- end
+def convert_to_fahrenheit(degrees, from_units)
+ if from_units == 'C'
+ degrees * 1.8 + 32
+ elsif from_units == 'K'
+ degrees * 9 / 5 - 459.67
+ elsif from_units == 'F'
+ degrees
end
+end
+def convert_to_kelvin(degrees, from_units)
+ if from_units == 'C'
+ degrees + 273.15
+ elsif from_units == 'K'
+ degrees
+ elsif from_units == 'F'
+ (degrees + 459.67) * 5 / 9
+ end
end
-def melting_point_of_substance(substance, wanted_temperature_unit)
- melting_points =
- {
- 'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
- 'silver' => 961.8, 'copper' => 1_085
- }
+def convert_between_temperature_units(degrees, from_units, to_units)
+ if to_units == 'C'
+ convert_to_celsius(degrees, from_units)
+ elsif to_units == 'F'
+ convert_to_fahrenheit(degrees, from_units)
+ elsif to_units == 'K'
+ convert_to_kelvin(degrees, from_units)
+ end
+end
- if melting_points[substance]
+MELTING_POINTS = {
+ 'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
+ 'silver' => 961.8, 'copper' => 1_085
+}
+
+def melting_point_of_substance(substance, wanted_temperature_unit)
+ if MELTING_POINTS[substance]
if wanted_temperature_unit == 'C'
- melting_points[substance]
+ MELTING_POINTS[substance]
elsif wanted_temperature_unit == 'K'
- convert_between_temperature_units(
- melting_points[substance], 'C', 'K'
- )
+ convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'K')
elsif wanted_temperature_unit == 'F'
- convert_between_temperature_units(
- melting_points[substance], 'C', 'F'
- )
+ convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'F')
end
- else
- 'Invalid input'
end
end
-def boiling_point_of_substance(substance, wanted_temperature_unit)
- boiling_points =
- {
- 'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
- 'silver' => 2_162, 'copper' => 2_567
- }
+BOILING_POINTS = {
+ 'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
+ 'silver' => 2_162, 'copper' => 2_567
+}
- if boiling_points[substance]
+def boiling_point_of_substance(substance, wanted_temperature_unit)
+ if BOILING_POINTS[substance]
if wanted_temperature_unit == 'C'
- boiling_points[substance]
+ BOILING_POINTS[substance]
elsif wanted_temperature_unit == 'K'
- convert_between_temperature_units(
- boiling_points[substance], 'C', 'K'
- )
+ convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'K')
elsif wanted_temperature_unit == 'F'
- convert_between_temperature_units(
- boiling_points[substance], 'C', 'F'
- )
+ convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'F')
end
- else
- 'Invalid input'
end
end

Добрин обнови решението на 14.10.2016 16:11 (преди над 7 години)

def convert_to_celsius(degrees, from_units)
if from_units == 'C'
degrees
elsif from_units == 'K'
degrees - 273.15
elsif from_units == 'F'
(degrees - 32) * 5 / 9
end
end
def convert_to_fahrenheit(degrees, from_units)
if from_units == 'C'
degrees * 1.8 + 32
elsif from_units == 'K'
degrees * 9 / 5 - 459.67
elsif from_units == 'F'
degrees
end
end
def convert_to_kelvin(degrees, from_units)
if from_units == 'C'
degrees + 273.15
elsif from_units == 'K'
degrees
elsif from_units == 'F'
(degrees + 459.67) * 5 / 9
end
end
def convert_between_temperature_units(degrees, from_units, to_units)
if to_units == 'C'
convert_to_celsius(degrees, from_units)
elsif to_units == 'F'
convert_to_fahrenheit(degrees, from_units)
elsif to_units == 'K'
convert_to_kelvin(degrees, from_units)
end
end
MELTING_POINTS = {
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
-def melting_point_of_substance(substance, wanted_temperature_unit)
+def melting_point_of_substance(substance, in_what_temperature_unit)
if MELTING_POINTS[substance]
- if wanted_temperature_unit == 'C'
+ if in_what_temperature_unit == 'C'
MELTING_POINTS[substance]
- elsif wanted_temperature_unit == 'K'
+ elsif in_what_temperature_unit == 'K'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'K')
- elsif wanted_temperature_unit == 'F'
+ elsif in_what_temperature_unit == 'F'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'F')
end
end
end
BOILING_POINTS = {
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
-def boiling_point_of_substance(substance, wanted_temperature_unit)
+def boiling_point_of_substance(substance, in_what_temperature_unit)
if BOILING_POINTS[substance]
- if wanted_temperature_unit == 'C'
+ if in_what_temperature_unit == 'C'
BOILING_POINTS[substance]
- elsif wanted_temperature_unit == 'K'
+ elsif in_what_temperature_unit == 'K'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'K')
- elsif wanted_temperature_unit == 'F'
+ elsif in_what_temperature_unit == 'F'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'F')
end
end
end

Така е доста по-добре :) А какво ще кажеш за идеята да има само 2 функции - вместо convert_to_celsius, convert_to_fahrenheit и convert_to_kelvin да има само convert_to_celsius и convert_from_celsius :) Така ако искаш да добавиш нова мерна единица няма да се налага да добавяш и още функции.

Добрин обнови решението на 15.10.2016 11:45 (преди над 7 години)

def convert_to_celsius(degrees, from_units)
if from_units == 'C'
degrees
elsif from_units == 'K'
degrees - 273.15
elsif from_units == 'F'
(degrees - 32) * 5 / 9
end
end
-def convert_to_fahrenheit(degrees, from_units)
- if from_units == 'C'
- degrees * 1.8 + 32
- elsif from_units == 'K'
- degrees * 9 / 5 - 459.67
- elsif from_units == 'F'
+def convert_from_celsius(degrees, to_units)
+ if to_units == 'C'
degrees
- end
-end
-
-def convert_to_kelvin(degrees, from_units)
- if from_units == 'C'
+ elsif to_units == 'K'
degrees + 273.15
- elsif from_units == 'K'
- degrees
- elsif from_units == 'F'
- (degrees + 459.67) * 5 / 9
+ elsif to_units == 'F'
+ degrees * 1.8 + 32
end
end
def convert_between_temperature_units(degrees, from_units, to_units)
- if to_units == 'C'
- convert_to_celsius(degrees, from_units)
- elsif to_units == 'F'
- convert_to_fahrenheit(degrees, from_units)
- elsif to_units == 'K'
- convert_to_kelvin(degrees, from_units)
+ if to_units == from_units
+ degrees
+ else
+ degrees_in_celsius = convert_to_celsius(degrees, from_units)
+ convert_from_celsius(degrees_in_celsius, to_units)
end
end
MELTING_POINTS = {
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
def melting_point_of_substance(substance, in_what_temperature_unit)
if MELTING_POINTS[substance]
if in_what_temperature_unit == 'C'
MELTING_POINTS[substance]
elsif in_what_temperature_unit == 'K'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'K')
elsif in_what_temperature_unit == 'F'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'F')
end
end
end
BOILING_POINTS = {
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
def boiling_point_of_substance(substance, in_what_temperature_unit)
if BOILING_POINTS[substance]
if in_what_temperature_unit == 'C'
BOILING_POINTS[substance]
elsif in_what_temperature_unit == 'K'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'K')
elsif in_what_temperature_unit == 'F'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'F')
end
end
end

Добрин обнови решението на 15.10.2016 12:31 (преди над 7 години)

def convert_to_celsius(degrees, from_units)
if from_units == 'C'
degrees
elsif from_units == 'K'
degrees - 273.15
elsif from_units == 'F'
(degrees - 32) * 5 / 9
end
end
def convert_from_celsius(degrees, to_units)
if to_units == 'C'
degrees
elsif to_units == 'K'
degrees + 273.15
elsif to_units == 'F'
degrees * 1.8 + 32
end
end
def convert_between_temperature_units(degrees, from_units, to_units)
if to_units == from_units
degrees
else
degrees_in_celsius = convert_to_celsius(degrees, from_units)
convert_from_celsius(degrees_in_celsius, to_units)
end
end
MELTING_POINTS = {
'water' => 0, 'ethanol' => -114, 'gold' => 1_064,
'silver' => 961.8, 'copper' => 1_085
}
-def melting_point_of_substance(substance, in_what_temperature_unit)
+def melting_point_of_substance(substance, in_which_temperature_unit)
if MELTING_POINTS[substance]
- if in_what_temperature_unit == 'C'
+ if in_which_temperature_unit == 'C'
MELTING_POINTS[substance]
- elsif in_what_temperature_unit == 'K'
+ elsif in_which_temperature_unit == 'K'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'K')
- elsif in_what_temperature_unit == 'F'
+ elsif in_which_temperature_unit == 'F'
convert_between_temperature_units(MELTING_POINTS[substance], 'C', 'F')
end
end
end
BOILING_POINTS = {
'water' => 100, 'ethanol' => 78.37, 'gold' => 2_700,
'silver' => 2_162, 'copper' => 2_567
}
-def boiling_point_of_substance(substance, in_what_temperature_unit)
+def boiling_point_of_substance(substance, in_which_temperature_unit)
if BOILING_POINTS[substance]
- if in_what_temperature_unit == 'C'
+ if in_which_temperature_unit == 'C'
BOILING_POINTS[substance]
- elsif in_what_temperature_unit == 'K'
+ elsif in_which_temperature_unit == 'K'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'K')
- elsif in_what_temperature_unit == 'F'
+ elsif in_which_temperature_unit == 'F'
convert_between_temperature_units(BOILING_POINTS[substance], 'C', 'F')
end
end
end