[Tutor] Code Problem

Ben Conklin benaconklin at gmail.com
Thu Mar 10 15:30:45 EST 2016


Hi,

I'm having troubles with my code, specifically at the area with the comment
mark. Basically you are to enter three sides of a triangle, and have it
show if it is a equilateral, isosceles, or right triangle. I have it so
that it makes s1 the longest side, and s2 and s3 the other 2 sides. The
right triangle equation should be right, but is not outputting anything.

def main():
    s1, s2, s3 = eval(input("Enter the three side lengths of a triangle: "))

    if s2 > s1:
        temp = s1
        s1 = s2
        s2 = temp
    if s3 > s1:
        temp = s1
        s1 = s3
        s3 = temp

    if s2 + s3 > s1:
        print("This is a triangle")
        if s1 == s2 and s2 == s3 and s3 == s1:
            print("This is an equilateral triangle")
        elif s1 == s2 or s2 == s3 or s3 == s1:
            print("This is an isosceles triangle")
        if s1**2 == s2**2 + s3**2: #This will not output a square triangle
when entered
            print("This is a right triangle")
    else:
        print("This is not a triangle")


More information about the Tutor mailing list