[英]Why doesn't my scalene triangle test work correctly?
Checking Scalene Triangle ( I am learning from http://www.pyschools.com ) 检查Scalene Triangle(我正在从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. 编写一个函数
isScalene(x, y, z)
,该函数接受三角形的3 sides
个边作为输入。 The function should return True if it is a scalene triangle. 如果该函数是一个斜角三角形,则该函数应返回True。 A scalene triangle has no equal sides.
斜角三角形没有相等的边。
Examples 例子
>>> isScalene(2, 4, 3)
True
>>> isScalene(3, 3, 3)
False
>>> isScalene(0, 2, 3)
False
>>> 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? 如果输入是2、3、5,该怎么办? (Hint: not a triangle at all!)
(提示:根本不是三角形!)
尝试更具表现力,我怀疑您的x!= y!= z是问题所在。
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! 您应该检查斜角三角形必须先是三角形!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.