Решение на Първа задача - температура и химични елементи от Натали Арабаджийска

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

Към профила на Натали Арабаджийска

Резултати

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

Код

def convert_between_temperature_units( degrees, unit_in, unit_out)
if unit_in == 'C' && unit_out == 'K'
return degrees + 273.15
elsif unit_in == 'C' && unit_out == 'F'
return degrees * 1.8 + 32
elsif unit_in == 'C' && unit_out == 'C'
return degrees
elsif unit_in == 'F' && unit_out == 'C'
return (degrees - 32) / 1.8
elsif unit_in == 'F' && unit_out == 'K'
return (degrees + 459.67) * 5 / 9
elsif unit_in == 'F' && unit_out == 'F'
return degrees
elsif unit_in == 'K' && unit_out == 'C'
return degrees - 273.15
elsif unit_in == 'K' && unit_out == 'F'
return degrees * 9 / 5 - 459.67
elsif unit_in == 'K' && unit_out == 'K'
return degrees
end
end
def melting_point_of_substance(substances, unit)
melting_points = {water: 0, ethanol: -114, gold: 1_064, silver: 961.8, copper: 1_085}
convert_between_temperature_units(melting_points.fetch(substances.to_sym), 'C', unit)
end
def boiling_point_of_substance(substances, unit2)
boiling_points = {water: 100, ethanol: 78.37, gold: 2_700, silver: 2_162, copper: 2_567}
convert_between_temperature_units(boiling_points.fetch(substances.to_sym), 'C', unit2)
end

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

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

Finished in 0.00781 seconds
17 examples, 0 failures

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

Натали обнови решението на 17.10.2016 00:28 (преди над 7 години)

+def convert_between_temperature_units( degrees, unit_in, unit_out)
+ if unit_in == 'C' && unit_out == 'K'
+ return degrees + 273.15
+ elsif unit_in == 'C' && unit_out == 'F'
+ return degrees * 1.8 + 32
+ elsif unit_in == 'C' && unit_out == 'C'
+ return degrees
+ elsif unit_in == 'F' && unit_out == 'C'
+ return (degrees - 32) / 1.8
+ elsif unit_in == 'F' && unit_out == 'K'
+ return (degrees + 459.67) * 5 / 9
+ elsif unit_in == 'F' && unit_out == 'F'
+ return degrees
+ elsif unit_in == 'K' && unit_out == 'C'
+ return degrees - 273.15
+ elsif unit_in == 'K' && unit_out == 'F'
+ return degrees * 9 / 5 - 459.67
+ elsif unit_in == 'K' && unit_out == 'K'
+ return degrees
+ end
+end
+
+def melting_point_of_substance(substances, unit)
+ melting_points = {water: 0, ethanol: -114, gold: 1_064, silver: 961.8, copper: 1_085}
+ convert_between_temperature_units(melting_points.fetch(substances.to_sym), 'C', unit)
+end
+
+def boiling_point_of_substance(substances, unit2)
+ boiling_points = {water: 100, ethanol: 78.37, gold: 2_700, silver: 2_162, copper: 2_567}
+ convert_between_temperature_units(boiling_points.fetch(substances.to_sym), 'C', unit2)
+end
+