# else command is not being read

3608 views
3

beginner here and I've been stuck on this for half an hour so even a badly optimized version is okay as long as it works. While doing the fourth exercise at the end of the page here I couldn't write that function.

So I need a function that takes a point (X, Y) and determines if it is inside a rectangle I've already set the proportions for.

``````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")
``````

Running this with a

``````r = Rectangle(Point(0, 0), 9, 3) #x, y, width, height
r.contains(74, 0)
``````

does not result in anything, python just skips it. I apologize if I missed something very clear, thanks!

You forgot to `print`.

You've left out `print` statements after both `else` statements, by the look of it

Thanks a lot, I have never felt so stupid. It worked!

2

``````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")
``````

i think you forgot to print as per your question reference! if you got solution please mark as a answer :)

posted this