您正在将输入就地转换为int,然后丢弃它。您应该将这些行更改为:length1 = int(raw_input('enter side 1\n'))
length2 = int(raw_input('enter side 2\n'))
length3 = int(raw_input('enter side 3\n'))
您的代码中还有一些其他语法错误。更正如下:def triangle_check(l1,l2,l3):
if (l1>l2+l3) or (l2>l1+l3) or (l3>l1+l2):
print 'No, the lengths wont form a triangle'
elif (l1==l2+l3) or (l2==l1+l3) or (l3==l1+l2):
print 'yes, it can form a degenerated triangle'
else:
print 'Yes, a triangle can be formed out of it'
length1 = int(raw_input('enter side 1\n'))
length2 = int(raw_input('enter side 2\n'))
length3 = int(raw_input('enter side 3\n'))
triangle_check(length1,length2,length3)
然而,这种编程方式令人困惑,我为您编写了一个更简单的算法:def check_valid_triangle(sides):
for side in sides:
other_sides = (sum(sides)-side)
if side > other_sides:
return 'No'
elif side == other_sides:
return 'Degenerated'
else:
return 'Yes'
sides = []
for i in range(3):
sides.append(int(raw_input('Enter a side:\n')))
print check_valid_triangle(sides)