如何修正if / else陈述

时间:2019-09-11 15:14:41

标签: if-statement

程序将不执行else命令

print ('This program will determine if three angles can form a triangle')
print ('Enter Angle 1')
degree1=input()

print ('Enter Angle 2')
degree2=input()

print ('Enter Angle 3')
degree3=input ()

degrees= int(degree1+degree2+degree3)

if (degrees>180):
    print ('Yes it does form a triangle as these angles are equal to 180')

else:
    print ('No, it does not form a triangle as these angles are less than 180')

打印是,它确实形成一个三角形,因为无论输入的数值如何,这些角度都等于180。

1 个答案:

答案 0 :(得分:0)

如果degree1degree2degree3是字符串,比它们之间的en +会导致字符串集中 not 。因此,1010加上10将得到值"101010",将其转换为int,然后与180进行比较。

在添加它们之前,您需要将每个degree输入转换为int