您的函数有错误,因为s未定义。您的代码应如下所示 -def perfsq(x): s = math.sqrt(x) # You didn't define s in your code if s == (math.floor(s)): # Just check if square root is an integer print('yes') return True else : print('No') return False