不可排序的类型:str()> int()

史蒂文·D

因此,我尝试制作的程序由等于右,等腰或钝三角形的三个输入组成,当我运行代码时,遇到了这个问题。我已经将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.")     
约瑟夫·法拉(Joseph Farah)

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

不可排序的类型:str()<int()

为什么在此代码中出现“ TypeError:不可排序类型:str()<int()”?

Python 2到3错误。TypeError:不可排序的类型:int()<= str()

二进制树问题:不可排序的类型:str()<int()

Python3-while ids> Stop:TypeError:不可排序的类型:str()> int()

类型错误:无法排序的类型:int() > str()

TypeError:不可排序的类型:int()> list()

TypeError:不可排序的类型:tuple()> int()

TypeError:不可排序的类型:list()> int()

Python - 类型错误:无法排序的类型:str() < int()

不可排序的类型:运行OneVsRest分类器中的dict()<= int()

类型错误:在冒泡排序中必须是 str,而不是 int

Int + Str 类型的python

为什么Python不可变类型(例如int,str或元组)需要使用__new __()而不是__init __()?

类型“ int”的参数不可迭代

Python不可排序类型:查找列表的最大值时,NoneType()> int()

类型错误:使用排序函数后“int”对象不可迭代(python 2.7)

保存Django表单会产生错误:无法排序的类型:int()> str()

类型错误:Int 对象不可迭代

Python类型错误:int对象不可迭代

类型错误:Int对象不可调用

类型错误:“int”对象不可下标?

java错误:不可转换类型必需int

difflib,类型错误int对象不可迭代

类型错误:int 对象不可调用

groupby python TypeError:不可排序的类型:tuple()<str()

类型错误:必须是 str,而不是 int;Python

获取类型错误:int 类型的参数在 Python 中不可迭代

'float / str / int'对象不可调用错误