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

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

Към профила на Николета Янкова

Резултати

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

Код

# first task
def convert_between_temperature_units(degree, x, y)
if x == 'C' && y == 'F'
degree * 1.8 + 32
elsif x == 'F' && y == 'C'
(degree - 32) / 1.8
elsif x == 'C' && y == 'K'
degree + 273.15
elsif x == 'K' && y == 'C'
degree - 273.15
elsif x == 'F' && y == 'K'
(degree + 459.67) / 1.8
elsif x == 'K' && y == 'F'
degree * 1.8 - 459.67
else puts "Wrong input!"
end
end
# second task
MELTING =
{
"water" => 0,
"ethanol" => -144,
"gold" => 1_064,
"silver" => 961.8,
"copper" => 1_085
}
def melting_point_of_substance(substance, unit)
if MELTING.key?(substance)
if unit == 'C'
puts MELTING[substance]
elsif unit == 'K' || unit == 'F'
temp = MELTING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end
# third task
BOILING =
{
"water" => 100,
"ethanol" => 78.37,
"gold" => 2_700,
"silver" => 2_162,
"copper" => 2_567
}
def boiling_point_of_substance(substance, unit)
if BOILING.key?(substance)
if unit == 'C'
puts BOILING[substance]
elsif unit == 'K' || unit == 'F'
temp = BOILING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end

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

▸ Покажи лога

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

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

▸ Покажи разликите
+# first task
+def convert_between_temperature_units(degree, x, y)
+ if x == 'C' && y == 'F'
+ degree * 1.8 + 32
+ elsif x == 'F' && y == 'C'
+ (degree - 32) / 1.8
+ elsif x == 'C' && y == 'K'
+ degree + 273.15
+ elsif x == 'K' && y == 'C'
+ degree - 273.15
+ elsif x == 'F' && y == 'K'
+ (degree + 459.67) / 1.8
+ elsif x == 'K' && y == 'F'
+ degree * 1.8 - 459.67
+ else puts "Wrong input!"
+ end
+end
+
+# second task
+MELTING =
+ {
+ "water" => 0,
+ "ethanol" => -144,
+ "gold" => 1_064,
+ "silver" => 961.8,
+ "copper" => 1_085
+ }
+
+def melting_point_of_substance(substance, unit)
+ if MELTING.key?(substance)
+ if unit == 'C' then puts MELTING[substance]
+ elsif unit == 'K' || unit == 'F'
+ temp = MELTING[substance]
+ puts convert_between_temperature_units(temp, 'C', unit)
+ else puts "Wrong input!"
+ end
+ else puts "Wrong input!"
+ end
+end
+
+# third task
+BOILING =
+ {
+ "water" => 100,
+ "ethanol" => 78.37,
+ "gold" => 2_700,
+ "silver" => 2_162,
+ "copper" => 2_567
+ }
+
+def boiling_point_of_substance(substance, unit)
+ if BOILING.key?(substance)
+ if unit == 'C' then puts BOILING[substance]
+ elsif unit == 'K' || unit == 'F'
+ temp = BOILING[substance]
+ puts convert_between_temperature_units(temp, 'C', unit)
+ else puts "Wrong input!"
+ end
+ else puts "Wrong input!"
+ end
+end

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

▸ Покажи разликите
# first task
def convert_between_temperature_units(degree, x, y)
if x == 'C' && y == 'F'
degree * 1.8 + 32
elsif x == 'F' && y == 'C'
(degree - 32) / 1.8
elsif x == 'C' && y == 'K'
degree + 273.15
elsif x == 'K' && y == 'C'
degree - 273.15
elsif x == 'F' && y == 'K'
(degree + 459.67) / 1.8
elsif x == 'K' && y == 'F'
degree * 1.8 - 459.67
else puts "Wrong input!"
end
end
# second task
MELTING =
{
"water" => 0,
"ethanol" => -144,
"gold" => 1_064,
"silver" => 961.8,
"copper" => 1_085
}
def melting_point_of_substance(substance, unit)
if MELTING.key?(substance)
- if unit == 'C' then puts MELTING[substance]
+ if unit == 'C'
+ puts MELTING[substance]
elsif unit == 'K' || unit == 'F'
temp = MELTING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end
# third task
BOILING =
{
"water" => 100,
"ethanol" => 78.37,
"gold" => 2_700,
"silver" => 2_162,
"copper" => 2_567
}
def boiling_point_of_substance(substance, unit)
if BOILING.key?(substance)
- if unit == 'C' then puts BOILING[substance]
+ if unit == 'C'
+ puts BOILING[substance]
elsif unit == 'K' || unit == 'F'
temp = BOILING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end