11/20 - Code looks identical to me but one gives an error, any help would be great


#1

Might be a typo but seems the same to me, let me know if you spot the reason!

The code that gives a pass:

class Point3D(object):
   def __init__(self, x, y, z):
       self.x = x
       self.y = y
       self.z = z
   def __repr__(self):
       return "(%d, %d, %d)" % (self.x, self.y, self.z) 
            
my_point = Point3D(1, 2, 3)
print my_point

The code below that according to me is identical prints correct (same as above) but gives me an error
Oops, try again. It looks like you didn't print "(1, 2, 3)".

class Point3D(object):
    def __init__(self,x,y,z):
        self.x = x
        self.y = y
        self.z = z
    def __repr__(self):
        return "(%d,%d,%d)" % (self.x,self.y,self.z)
        
my_point = Point3D(1,2,3)
print my_point

#2

Hi @scriptmaster83175 ,

The two code examples produce slightly different output. The __repr__ methods are not the same. The first example produces spaces after the commas in the output, but the second produces no spaces.

Thanks for the nice code formatting; it looks great, and is easy to read. :smile:


#3

@appylpye yes the spaces definitely was the only different thing but this definitely should not affect the outcome but only the readability and consistency for down the line (good coding practice) but not function surely?


#4

thanks applypye...so we should make a space after commas to pass this...no space no pass :grin: :smile: subhanallah..