Answer the question
In order to leave comments, you need to log in
Which code is better out of these 2 options?
Your opinion:
Option 1
puts "Value A"
first = gets.to_f
puts "Value B"
second = gets.to_f
puts "Value C"
third = gets.to_f
triangle_array = [first.to_f, second.to_f, third.to_f]
if triangle_array.sort[2]**2 == (triangle_array.sort[0]**2) + (triangle_array.sort[1]**2)
puts "Triangle is rectangular" # Basic values for this result is 6,8,10
else
puts "Triangle not rectangular"
end
if triangle_array.sort[0] == triangle_array.sort[1] || triangle_array.sort[0] == triangle_array [2] || triangle_array.sort[1] == triangle_array [2]
puts "Triangle is also isosceles"
else
puts "Triangle is also not isosceles"
end
puts 'Давайте узнаем ваш треугольник'
puts 'равнобедренный, прямоугольный или не прямоугольный'
puts 'Введите значение A'
a = gets.to_i
puts 'Введите значение B'
b = gets.to_i
puts 'Введите значение C'
c = gets.to_i
if a > b && a > c
hypotenuse = a
cathetus1 = b
cathetus2 = c
elsif b > a && b > c
hypotenuse = b
cathetus1 = a
cathetus2 = c
elsif c > b && c > a
hypotenuse = c
cathetus1 = a
cathetus2 = b
end
if a == b && a == c
puts 'Треугольник равнобедренный, но не прямоугольный'
elsif hypotenuse**2 == cathetus1**2 + cathetus2**2
puts 'Треугольник прямоугольный'
else
puts 'Треугольник НЕ прямоугольный'
end
Answer the question
In order to leave comments, you need to log in
The first, at least because of the understandable names of the variables.
Secondly, why is there no option "rectangular and isosceles" in the second option, but only "isosceles but not rectangular"? Unlike the first option.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question