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

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

Към профила на Петър Скорчелиев

Резултати

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

Код

def convert_between_temperature_units(degrees, start_unit, result_unit)
if start_unit == result_unit
degrees
elsif start_unit == 'C' && result_unit == 'K'
degrees + 273.15
elsif start_unit == 'K' && result_unit == 'C'
degrees - 273.15
elsif start_unit == 'C' && result_unit == 'F'
degrees * 9.to_f / 5 + 32
elsif start_unit == 'F' && result_unit == 'C'
(degrees - 32) * 5.to_f / 9
elsif start_unit == 'K' && result_unit == 'F'
(degrees - 273.15) * 9.to_f / 5 + 32
elsif start_unit == 'F' && result_unit == 'K'
(degrees - 32) * 5.to_f / 9 + 273.15
end
end
def melting_point_of_substance(substance, unit)
celsius_melting_points = {
'water' => 0,
'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085
}
convert_between_temperature_units(celsius_melting_points[substance], 'C', unit)
end
def boiling_point_of_substance(substance, unit)
celsius_boiling_points = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567
}
convert_between_temperature_units(celsius_boiling_points[substance], 'C', unit)
end

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

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

Finished in 0.00782 seconds
17 examples, 0 failures

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

Петър обнови решението на 17.10.2016 14:51 (преди над 7 години)

+def convert_between_temperature_units(degrees, start_unit, result_unit)
+ if start_unit == result_unit
+ degrees
+
+ elsif start_unit == 'C' && result_unit == 'K'
+ degrees + 273.15
+
+ elsif start_unit == 'K' && result_unit == 'C'
+ degrees - 273.15
+
+ elsif start_unit == 'C' && result_unit == 'F'
+ degrees * 9.to_f / 5 + 32
+
+ elsif start_unit == 'F' && result_unit == 'C'
+ (degrees - 32) * 5.to_f / 9
+
+ elsif start_unit == 'K' && result_unit == 'F'
+ (degrees - 273.15) * 9.to_f / 5 + 32
+
+ elsif start_unit == 'F' && result_unit == 'K'
+ (degrees - 32) * 5.to_f / 9 + 273.15
+
+ end
+end
+
+def melting_point_of_substance(substance, unit)
+
+ celsius_melting_points = {
+ 'water' => 0,
+ 'ethanol' => -114,
+ 'gold' => 1064,
+ 'silver' => 961.8,
+ 'copper' => 1085
+ }
+ convert_between_temperature_units(celsius_melting_points[substance], 'C', unit)
+end
+
+def boiling_point_of_substance(substance, unit)
+
+ celsius_boiling_points = {
+ 'water' => 100,
+ 'ethanol' => 78.37,
+ 'gold' => 2700,
+ 'silver' => 2162,
+ 'copper' => 2567
+ }
+ convert_between_temperature_units(celsius_boiling_points[substance], 'C', unit)
+end