Python 2.7 获取以下错误消息TypeError:在字符串格式化过程中并非所有参数都已转换

Python 2.7 获取以下错误消息TypeError:在字符串格式化过程中并非所有参数都已转换,python-2.7,python-3.x,Python 2.7,Python 3.x,我试图从用户那里读取一个带有坐标和半径的圆,并试图返回它的详细信息,但在执行这段代码时,我得到了一个错误 import math class Circle(): def __init__(self, centre, radius): self.centre = centre self.radius = radius self.area1=math.pi*radius*radius def __str__(self):

我试图从用户那里读取一个带有坐标和半径的圆,并试图返回它的详细信息,但在执行这段代码时,我得到了一个错误

import math
class Circle():
    def __init__(self, centre, radius):
        self.centre = centre
        self.radius = radius
        self.area1=math.pi*radius*radius

    def __str__(self):
        return ("A Circle which has centre at " + "(" + "%0.6f" % (self.centre)+")" + "and its radius " + "%0.6f" % (self.radius))



if __name__ == "__main__":
    print("CHECKING THE FUNCTIONALITY OF CIRCLE CLASS")
    x = float(input("Enter x coordinate of first circle's centre: "))
    y = float(input("Enter y coordinate of the first circle's centre: "))
    r = float(input("Enter first circle's radius: "))
    pointx1 = x
    pointy1 = y
    radius1 = r
    centre_1 = (pointx1,pointy1)
    first_circle = Circle(centre_1, r)
    print(first_circle)
错误消息显示:

File "C:/Users/Deepak/Desktop/part2.py", line 9, in __str__
return ("A Circle which has centre at " + "(" + "%0.6f" % (self.centre)+")" 
+ "and its radius " + "%0.6f" % (self.radius))
TypeError: not all arguments converted during string formatting

我不明白这里出了什么问题。我急需帮助。如有任何帮助,我们将不胜感激。

请尝试首先汇编整个格式字符串,然后通过一个%运算符传递所有数据。尝试了很多次,但均无效。在
self.center
中,您有一个元组。这似乎与浮点格式字符串不兼容。尝试将其拆分为
“(%0.6f,%0.6f)”%self.center
。这很有效。非常感谢您首先组装整个格式字符串,然后通过一个%运算符传递所有数据。尝试了很多次,但都无效。在
self.center
中,您有一个元组。这似乎与浮点格式字符串不兼容。尝试将其拆分为
“(%0.6f,%0.6f)”%self.center
。非常感谢