Решение на Първа задача - температура и химични елементи от Емине Башева

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

Към профила на Емине Башева

Резултати

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

Код

def convert_between_temperature_units(degree, from_unit, to_unit)
if from_unit == 'C'
if to_unit == 'F'
degree * 1.8 + 32
elsif to_unit == 'K'
degree + 273.15
else
degree
end
elsif from_unit == 'F'
if to_unit == 'C'
(degree - 32) / 1.8
elsif to_unit == 'K'
(degree + 459.67) * 5.0 / 9.0
else
degree
end
elsif from_unit == 'K'
if to_unit == 'C'
degree - 273.15
elsif to_unit == 'F'
degree * 9.0 / 5.0 - 459.67
else
degree
end
end
end
def melting_point_of_substance(substance, unit)
case substance
when 'water'
convert_between_temperature_units(0, 'C', unit)
when 'ethanol'
convert_between_temperature_units(-114, 'C', unit)
when 'gold'
convert_between_temperature_units(1_064, 'C', unit)
when 'silver'
convert_between_temperature_units(961.8, 'C', unit)
when 'copper'
convert_between_temperature_units(1_085, 'C', unit)
end
end
def boiling_point_of_substance(substance, unit)
case substance
when 'water'
convert_between_temperature_units(100, 'C', unit)
when 'ethanol'
convert_between_temperature_units(78.37, 'C', unit)
when 'gold'
convert_between_temperature_units(2_700, 'C', unit)
when 'silver'
convert_between_temperature_units(2_162, 'C', unit)
when 'copper'
convert_between_temperature_units(2_567, 'C', unit)
end
end

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

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

Finished in 0.00912 seconds
17 examples, 0 failures

История (1 версия и 0 коментара)

Емине обнови решението на 17.10.2016 15:57 (преди около 8 години)

+def convert_between_temperature_units(degree, from_unit, to_unit)
+ if from_unit == 'C'
+ if to_unit == 'F'
+ degree * 1.8 + 32
+ elsif to_unit == 'K'
+ degree + 273.15
+ else
+ degree
+ end
+ elsif from_unit == 'F'
+ if to_unit == 'C'
+ (degree - 32) / 1.8
+ elsif to_unit == 'K'
+ (degree + 459.67) * 5.0 / 9.0
+ else
+ degree
+ end
+ elsif from_unit == 'K'
+ if to_unit == 'C'
+ degree - 273.15
+ elsif to_unit == 'F'
+ degree * 9.0 / 5.0 - 459.67
+ else
+ degree
+ end
+ end
+end
+
+def melting_point_of_substance(substance, unit)
+ case substance
+ when 'water'
+ convert_between_temperature_units(0, 'C', unit)
+ when 'ethanol'
+ convert_between_temperature_units(-114, 'C', unit)
+ when 'gold'
+ convert_between_temperature_units(1_064, 'C', unit)
+ when 'silver'
+ convert_between_temperature_units(961.8, 'C', unit)
+ when 'copper'
+ convert_between_temperature_units(1_085, 'C', unit)
+ end
+end
+
+def boiling_point_of_substance(substance, unit)
+ case substance
+ when 'water'
+ convert_between_temperature_units(100, 'C', unit)
+ when 'ethanol'
+ convert_between_temperature_units(78.37, 'C', unit)
+ when 'gold'
+ convert_between_temperature_units(2_700, 'C', unit)
+ when 'silver'
+ convert_between_temperature_units(2_162, 'C', unit)
+ when 'copper'
+ convert_between_temperature_units(2_567, 'C', unit)
+ end
+end