当我运行该函数时,在完成程序后,它在终端中没有显示。我该如何防止这种情况发生
我尝试使用return,但是找不到正确的使用方式。
class Point :
def __init__(self, x, y):
self.x = x
self.y = y
def check_quadrant(self):
if self.x > 0 and self.y > 0:
print("The Point lies in the First Quadrant.")
if self.x < 0 < self.y:
print("The Point lies in the Second Quadrant.")
if self.x < 0 and self.y < 0:
print("The Point lies in the Third Quadrant.")
if self.x > 0 > self.y:
print("The Point lies in the Fourth Quadrant.")
if self.x > 0 and self.y == 0 or self.x < 0 and self.y == 0:
print("Point lies on the X-Axis.")
if self.x == 0 and self.y < 0 or self.x == 0 and self.y > 0:
print("The Point lies on the Y-Axis.")
if self.x == 0 and self.y == 0 :
print("The Point lies on the Origin")
return
try:
x_cor = int(input("X-Coordinate = "))
y_cor = int(input("Y-Coordinate = "))
except ValueError:
print("Only INPUT Integers !")
point1 = Point(x_cor, y_cor)
print(Point.check_quadrant(point1))
预期结果: X坐标= 0 Y坐标= 0 重点在原点上
答案 0 :(得分:2)
您只需要删除print
。更改:
print(Point.check_quadrant(point1))
收件人:
Point.check_quadrant(point1)
check_quadrant
方法返回None
,您通常不会看到它,但是在您的情况下,您是显式打印它。