简体   繁体   中英

Why doesn't my scalene triangle test work correctly?

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
>>> 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!)

尝试更具表现力,我怀疑您的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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM