+ 1
Why isn't this code working?
I'm practising my codes, and outta nowawhere this one doesn't work and i can't for the life of me understand why. Can you help? Here it is: ############### class Dog: def __init__(self, legs, colour): self.legs = legs self.colour = colour def get_both(self): legs+colour fido = Dog(4, "brown") spot = Dog(3, "mostly yellow") print (fido.get_both) ###############
2 Answers
+ 2
Dogao Zika Fixed it.
class Dog:
def __init__(self, legs, colour):
self.legs = legs
self.colour = colour
def get_both(self):
return (self.legs, self.colour)
fido = Dog(4, "brown")
print(fido.get_both())
+ 1
it still says this Traceback (most recent call last):
File "C:\Users\mathe\Desktop\test.py", line 12, in <module>
print(fido.get_both())
File "C:\Users\mathe\Desktop\test.py", line 7, in get_both
return (legs, colour)
NameError: name 'legs' is not defined