Python - unorderable types: Car() > int
<p>I keep getting this error: </p>

<pre><code>in move_the_car

if self.car_fuel &gt; x_count + y_count:

TypeError: unorderable types: Car() &gt; int()
</code></pre>

<p>From this code:</p>

<pre><code>if self.fuel &gt; x_count + y_count:
</code></pre>

<p>I've heard global can resolve this, but I'm not sure how. If anyone has any other solutions or answer, I will be very grateful. Also I am a beginner in coding and python, so my code may not be written the best, but I am always looking to improve.</p>

<p>Entire code</p>

<pre><code>class Car:

    def __init__(self, id_, fuel, x_pos, y_pos):
        """
        @type self: Car
        @type id_: str
        @type fuel: int
        @rtype: None
        """
        self.id = id_
        self.fuel = fuel
        self.x_pos = x_pos
        self.y_pos = y_pos


    @property
    def id_(self):
        return self.id

    @id_.setter
    def id_(self, value):
        if value != str:
            raise ValueError()
        else:
            self.id = value

    @property
    def car_fuel(self):
        return self.fuel

    @car_fuel.setter
    def car_fuel(self, value):
         if value &lt; 0:
             raise ValueError()
         else:
             self.fuel = value

    def move_the_car(self, id_, new_x_pos, new_y_pos):
        """
        @type self: Car
        @type id_: str
        @type new_x_pos: int
        @type new_y_pos: int

        @rtype: None
        """

        x_count = 0
        y_count = 0


        while x_count != abs(new_x_pos):
            x_count += 1

        while y_count != abs(new_y_pos):
            y_count += 1

        # if fuel level is greater than the movement counter, then return
        # the new x and y positions
        if self.fuel &gt; x_count + y_count:
            new_fuel_level = self._fuel - (x_count + y_count)
            self._fuel = new_fuel_level
            self.x_pos = new_x_pos
            self.y_pos = new_y_pos
            new_pos = [self.x_pos, self.y_pos]
            return new_pos
        elif 0 &lt; self.fuel &lt; (x_count + y_count):
            new_pos = [self.x_pos, self.y_pos]
            return new_pos
        elif self.fuel &lt;= 0:
            old_pos = [self.x_pos, self.y_pos]
            return old_pos

        else:
            return None
</code></pre>

<p><strong>Example:</strong></p>

<pre><code>test_car = Car('car1', 10, 0, 0) #id = 'car1', fuel = 10, x_pos = 0, y_pos = 0
print(test_car) # works fine
print(test_car.car_fuel) #works fine, gives 10
print(test_car.fuel) # works fine, gives 10

print(test_car.move_the_car('car1', 2, 3))  # works fine, gives [2,3]
</code></pre>

<p><strong>I also call this class in another class, this may be the problem.</strong></p>

<pre><code>class CarManager:

def __init__(self):
    self._cars = {}


def add_car(self, id_, fuel):
    """Add a new car to the system"""


    if id_ not in self._cars:
        self._cars[id_] = Car(id_, fuel, 0, 0)
        return self._cars[id_]
    else:
        return None

def move_car(self, id_, new_x, new_y):
    """Move the car with the given id.
    """

    if id_ not in self._cars:
        return None

    else:
        car_pos = Car(id_, self._cars[id_], new_x, new_y)
        return car_pos.move_the_car(id_, new_x, new_y)
</code></pre>

<p><strong>The last part may be the problem:</strong></p>

<pre><code>def move_car(self, id_, new_x, new_y):
    """Move the car with the given id.
    """

    if id_ not in self._cars:
        return None

    else:
        car_pos = Car(id_, self._cars[id_], new_x, new_y)
        return car_pos.move_the_car(id_, new_x, new_y)
</code></pre>

<blockquote>
  <p>if self.car_fuel > x_count + y_count:</p>
  
  <p>TypeError: unorderable types: Car() > int()</p>
</blockquote>

<p>This is telling you that at some point you've assigned a <em>Car</em> instance to <code>self.car_fuel</code> when you likely intended to assign an <em>int</em> or a <em>float</em>.</p>

python