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

时间:2017-11-02 11:56:08

标签: 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):
        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

我无法理解这里出了什么问题。我急需帮助。非常感谢你的帮助。

0 个答案:

没有答案