'Making a rect following another rect [duplicate]

I'd like an instance of UFO class (let's name it ufo) to follow an instance of Ship class (ship). The relevant code is contained in chase_ship method of UFO class. After running a game, the ufo chase the ship for while and then stopped in the place. What's wrong with my method?

ufo.py

class UFO():
---snip---
    def chase_ship(self):
        """Trace and follow a ship."""
        if self.rect.x != self.ship.rect.x:
            #Move toward a ship horizontally.
            if self.rect.x < self.ship.rect.x:
                self.rect.x += self.speed
            else:
                self.rect.x -= self.speed
        if self.rect.y != self.ship.rect.y:
            #Move toward a ship vertically.
            if self.rect.y < self.ship.rect.y:
                self.rect.y += self.speed
            else:
                self.rect.y -= self.speed
            
            
        
        

        


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source