1

Im very new to python and working on this code for a school project. I'm getting some error messages and having issues correcting them. Any guidance would be much appreciated.

enter code here
class Mammal():
def __init__(self, name='', size='', sound=''):
 self.name = name
 self.size = size
 self.sound = sound
class Gorilla(Mammal):
 def __init__(self, name, size,sound, type):
 super().__init__(name, size, sound)
 self.type = type
Silverback = Gorilla(Barney, large, grunts)
print("The gorilla type is"+ Gorilla.type)
print(" The gorilla's name is"+ Gorilla.name)
print(' The gorilla is'+ Gorilla.size)
print('the gorilla sound is'+ Gorilla.sound )
class Bear(Mammal):
 def __init__(self, name, size,sound, type):
 super().__init__(name, size, sound)
 self.type = type
Polar = Bear(Henry, large, roar)
print("The bear type is"+ Bear.type)
print(" The bear's name is"+ Bear.name)
print(' The bear is'+ Bear.size)
print('the bear says'+ Bear.sound )
b = Bear()
g = Gorilla()
if (b == g):
 print(b.getGenus() + " and " + g.getGenus() + " are of the same genus")
else:
 print(b.getGenus() + " and " + g.getGenus() + " are *not* of the same 
genus")
def listenToMammal(Mammal):
 print(Mammal.makeNoise())
listenToMammal(B)
listenToMammal(G)

The code is only running to line 13 and giving me the error: Traceback (most recent call last): File "C:/Users/Owner/PycharmProjects/pythonProject/main.py", line 13, in Silverback = Gorilla(Barney, large, grunts) NameError: name 'Barney' is not defined

asked Sep 6, 2020 at 22:45
1
  • 1
    You never defined Barney Commented Sep 6, 2020 at 22:56

1 Answer 1

1

Because of it searching variable called Barney and there' s no variable you defined. For arguments you jhave to pass with quotes or define before you intiliaze the object

silverback = Gorilla("Barney", "large", "grunts") To print it don't use the class name use the variable you initialized the object.

Print(" the Gorilla type is "+silverback.type)

answered Sep 6, 2020 at 22:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.