Python 未读取else命令
初学者在这里,我已经被困在这半个小时,所以即使是一个糟糕的优化版本是好的,只要它的工作。 在页面末尾做第四个练习时,我无法编写该函数 所以我需要一个函数,它取一个点(X,Y),并确定它是否在一个我已经设置了比例的矩形内Python 未读取else命令,python,python-3.x,Python,Python 3.x,初学者在这里,我已经被困在这半个小时,所以即使是一个糟糕的优化版本是好的,只要它的工作。 在页面末尾做第四个练习时,我无法编写该函数 所以我需要一个函数,它取一个点(X,Y),并确定它是否在一个我已经设置了比例的矩形内 def contains(self, x, y): if x < self.width and x >= 0: if y < self.height and y >= 0: print("The point
def contains(self, x, y):
if x < self.width and x >= 0:
if y < self.height and y >= 0:
print("The point is in the rectangle")
else:
("The point is not in the rectangle")
else:
("The point is not in the rectangle")
不会产生任何结果,python只是跳过了它。
如果我错过了一些非常清楚的东西,我道歉,谢谢 def包含(self、x、y):
def contains(self, x, y):
if x < self.width and x >= 0:
if y < self.height and y >= 0:
print("The point is in the rectangle")
else:
print("The point is not in the rectangle")
else:
print("The point is not in the rectangle")
如果x=0:
如果y=0:
打印(“点位于矩形中”)
其他:
打印(“点不在矩形中”)
其他:
打印(“点不在矩形中”)
我想你忘了根据你的问题参考打印!
如果你得到了解决方案,请标记为答案:)你忘了
打印
。在和
语句之后,你漏掉了打印
语句,从它的外观来看,我从来没有觉得这么愚蠢。成功了!顺便说一句,如果x=0:
def contains(self, x, y):
if x < self.width and x >= 0:
if y < self.height and y >= 0:
print("The point is in the rectangle")
else:
print("The point is not in the rectangle")
else:
print("The point is not in the rectangle")