Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error: expected an indented block, python

so, im following a course called Python Game Development™ : Build 11 Total Games.
and I came across an error saying expected an indented block and I don’t know how to fix it as the person who wrote the code has the same exact code as me. so, I don’t get whats wrong because they had no error, and I did.
this is my code:

import collections

import math

import os

def path(filename):

    filepath = os.path.realpath(__file__)

    dirpath = os.path.dirname(filepath)

    fullpath = os.path.join(dirpath,filename)

    return fullpath

def line(a,b,x,y):

    import turtle

    turtle.up()

    turtle.goto(a,b)

    turtle.down()

    turtle.goto(x,y)

class vector(collections.Sequence):

    PRECISION = 6

    __slots__ = ('_x','_y','_hash')

    def __init__(self,x,y):

        self._hash = None

        self._x = round(x,self.PRECISION)

        self._y = round(y,self.PRECISION)

    @property

    #getter

    def x(self):

        return self._x

    @x.setter

    def x(self,value):

        if self._hash is not None:

            raise ValueError('Cannot set x after hashing')

        self._x = round(value,self.PRECISION)

    @property

    def y(self):

        return self._y

    @y.setter

    def y(self,value):

        if self._hash is not None:

            raise ValueError('Cannot set y after hashing')

        self._y = round(value,self.PRECISION)

    def __hash__(self):

        

        if self._hash is None:

            pair = (self.x,self.y)

            self._hash = hash(pair)

        return self._hash

    def __len__(self):

        return 2

    def __getitem__(self,index):

        if index == 0:

            return self.x

        elif index == 1:

            return self.y

        else:

            raise IndexError

    def copy(self):

        type_self = type(self)

        return type_self(self.x,self.y)

    def __eq__(self,other):

        if isinstance(other,vector):

            return self.x == other.x and self.y == other.y

        return NotImplemented

    def __ne__(self,other):

        if isinstance(other,vector):

            return self.x != other.x and self.y != other.y

        return NotImplemented

    def __iadd__(self,other):

    def __add__(self,other):

the error is on def add(self,other):. I’m a beginner programmer. so if u could help me out with this error, it would be great. thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you copied the code, you forgot to copy the the business logic in iadd and add, if you add that the error will disappear.

def __iadd__(self,other):
   # Your code goes here

def __add__(self,other):
   # Your code goes here

Note: Replace # Your code goes here with the actual business logic.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading