In this code, there's a Person class that has an attribute name, which gets set when constructing the object. Fill in the blanks so that 1) when an instance of the class is created, the attribute gets set correctly, and 2) when the greeting() method is called, the greeting states the assigned name. mtino 1-class Person: 2 - def __init__(self, name): self.name = def greeting(self): # Should return "hi, my name is " followed by the name of the Person. return Run 8 # Create a new instance with a name of your choice 9 some_person = 10 # Call the greeting method 11 print (some_person. ) 12 Press ESC to exit the code block at any time

Respuesta :

Answer:

Explanation:

The following code is written in Python. It creates a Person class and creates the constructor which takes in the name of the person for that instance, as well as a greeting method which outputs the desired "Hi, my name is" string with the name of that person. The output of the code can be seen in the attached picture below. I have created a person object called John and called the greeting method so that you can see the output.

class Person:

   name = ''

   def __init__(self, name):

       self.name = name

   def greeting(self):

       print('Hi, my name is ' + self.name)

Ver imagen sandlee09

The code containing the Person class definition and the greeting is found in the attached image

The Person class has a single instance field name that stores the name of the person.

The instance initializer, __init__, accepts an argument, name, and saves the value in the name attribute of the Person class.

The Person class also has a greeting method that is called by the main code segment. The main code segment creates a Person object, and calls it in the print function to display the greeting with the person's name.

Learn more about classes in Python here https://brainly.com/question/21065208

Ver imagen batolisis
ACCESS MORE
EDU ACCESS