Ruby Koan 151 raising exceptions

后端 未结 30 1630
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:34

I\'m going through the ruby koans, I\'m on 151 and I just hit a brick wall.

Here is the koan:

# You need to write the triangle method in the file \'trian         


        
30条回答
  •  花落未央
    2021-01-31 15:10

    You definately do not update the TriangleError class - I am stuck on 152 myself. I think I need to use the pythag theorem here.

    def triangle(a, b, c)
      # WRITE THIS CODE
    
      if a == 0 || b == 0 || c == 0
        raise TriangleError
      end
    
      # The sum of two sides should be less than the other side
      if((a+b < c) || (a+c < b) || (b+c < a))
        raise TriangleError
      end
      if a==b && b==c
        return :equilateral
      end
      if (a==b && a!=c) || (a==c && a!=b) || (b==c && b!=a)
        return :isosceles
      end
      if(a!=b && a!=c && b!=c)
        return :scalene
      end
    
    
    end
    
    # Error class used in part 2.  No need to change this code.
    class TriangleError < StandardError
    end
    

提交回复
热议问题