type函数返回的不是数据的类型吗,为什么不能参与运算
import math
a=1
while 1==1:
if type(math.sqrt(a+100))==class 'int' and type(math.sqrt(a+168))==class 'int' :
print(a)
break
type函数返回的不是数据的类型吗,为什么不能参与运算
import math
a=1
while 1==1:
if type(math.sqrt(a+100))==class 'int' and type(math.sqrt(a+168))==class 'int' :
print(a)
break
type方法返回的数据类型是一个type对象,type对象不能直接用==比较是否相等,你可以转为str字符串后再判断是否相等。其次math.sqrt的输出结果是float类型的。代码修改如下,请采纳哦
import math
a = 1
while 1 == 1:
print(type(math.sqrt(a + 100)))
if str(type(math.sqrt(a + 100))) == "<class 'float'>" and str(type(math.sqrt(a+168))) == "<class 'float'>":
print(a)
break