Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未读取else命令_Python_Python 3.x - Fatal编程技术网

Python 未读取else命令

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

初学者在这里,我已经被困在这半个小时,所以即使是一个糟糕的优化版本是好的,只要它的工作。 在页面末尾做第四个练习时,我无法编写该函数

所以我需要一个函数,它取一个点(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:
            ("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")