Checking Scalene Triangle ( I am learning from http://www.pyschools.com)
I do not know what I am wrong ,Because I could not pass this test.
Write a function isScalene(x, y, z)
that accepts the 3 sides
of a triangle as inputs. The function should return True if it is a scalene triangle. A scalene triangle has no equal sides.
Examples
>>> isScalene(2, 4, 3)
True
>>> isScalene(3, 3, 3)
False
>>> isScalene(0, 2, 3)
False
&开发者_开发技巧gt;>> isScalene(2, 2, 3)
False
My function define like this :
def isScalene(x, y, z):
if(x > 0 and y >0 and z> 0):
if(x!=y!=z):
return True
else:
return False
else:
return False
Could anyone give me a tip?
What if the inputs are 2, 3, 5? (Hint: not a triangle at all!)
Try being more expressive, I suspect your x!=y!=z is the problem.
if ( ( x != y ) and ( x != z ) and ( y !=z ) )
def isScalene(x, y, z):
if x <= 0 or y <= 0 or z <= 0:
return False
if x + y > z and x - y < z:
if x !=y != z:
return True
return False
you should check the scalene triangle must be a triangle first!
精彩评论