Computer Science, asked by dsbshah, 4 months ago

What is wrong with the following:

class Dog():
def __init__(self, new_name):
""" Constructor.
Called when creating an object of this type """

name = new_name
print("A new dog is born!")

# This creates the dog
my_dog = Dog("Rover")​

Answers

Answered by Kshitij2312
1

Answer:

Line 7

self.name = new_name

Explanation:

We need to specify that name is an attribute of the dog class. To do this, we need to add the self. prefix before creating a name method that gets data from the parameter new_name passed in the __init__() function.

Similar questions