Complete the code to define an instance method that returns the name of the person.
class Person: def __init__(self, name): self.name = name def get_name(self): return self.[1]
The instance method accesses the instance variable name using self.name. Here, the blank is for the attribute name, so just name is correct.
Complete the code to call the instance method greet on the object p.
class Person: def greet(self): return "Hello!" p = Person() message = p.[1]()
To call an instance method, use the method name without parentheses inside the attribute access, then add parentheses after. So p.greet() is correct, and the blank is just the method name greet.
Fix the error in the instance method by completing the blank with the correct parameter name.
class Person: def __init__([1], name): self.name = name
The first parameter of instance methods must be self to refer to the instance.
Fill both blanks to create an instance method that returns the person's age plus 5.
class Person: def __init__(self, age): self.age = age def future_age(self): return self.[1] [2] 5
The method returns the current age plus 5, so the attribute age and the plus operator + are needed.
Fill all three blanks to create a method that returns a greeting with the person's name in uppercase.
class Person: def __init__(self, name): self.name = name def greet(self): return f"Hello, [1]!".[2]().[3]()
lower() instead of upper().The method returns a greeting with the name in uppercase and stripped of whitespace. So self.name is the name, strip() removes spaces, and upper() converts to uppercase.