因此,我尝试制作的程序由等于右,等腰或钝三角形的三个输入组成,当我运行代码时,遇到了这个问题。我已经将int()放在所有内容的前面。我究竟做错了什么?
angle_1 = input("What is the degree of the first angle? ")
angle_2 = input("What is the degree of the second angle? ")
angle_3 = input("What is the degree of the third angle? ")
if int(angle_1 or angle_2 or angle_3) == 90:
print("This is a right triangle.")
elif int((angle_1 or angle_2 or angle_3) > 90) and int((angle_1 or angle_2 or angle_3) < 180):
print("This is an obtuse triangle.")
else:
print("This is an acute triangle.")
if
语句中的语法很奇怪。我会列出一个角度名称,然后遍历它们。
angle_1 = input("What is the degree of the first angle? ")
angle_2 = input("What is the degree of the second angle? ")
angle_3 = input("What is the degree of the third angle? ")
# This will be looped through
angle_list=[angle_1, angle_2, angle_3] # This will be looped through
for angle in angle_list: # Goes through each inputted angle.
if angle == 90:
print 'This triangle is right.'
break
elif angle > 90:
print 'This triangle is obtuse.'
break
else:
print 'This is an acute triangle.'
break
为了将来参考,在使用新概念时,您可能希望直接参考文档。or
是逻辑运算符,而不是布尔值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句