Recommand · May 14, 2022 0

Python Programming (user-defined methods)

I am trying to find out what is the problem/error from my code, how to do this for used-defined? (Expected method ‘get_name’ to be defined as: def get_name(self): … this is my code so far:

from datetime import date

class Person:
    def __init__(self, name, height, birthdate):
# Set the name, height and birthdate of the
  # newly created Person object to the argument
  # objects.
  # - name is a str
  # - height is an int object in centimetres
  # - birthdate is a date object from the
  # module datetime = name
        self.height = height
        self.birthdate = birthdate
def get_name(self):
# Return the name of the person as a str.
def get_height(self):
# Return the hight of the person in cm as an
  # int.
    return self.height  
def get_age(self):
# Return the age of the person in years.
    birthdate = self.birthdate
    today =
    subyear = 0
    if today.month < birthdate.month or (today.month == and <=
        subyear = 1
    self.age = (today.year - (birthdate.year + subyear))
    return self.age
def get_description(self):
 # Return a string object of the form: Name is
 # N cm high and is M years old, where N and M
 # are integers:
    return + ' is ' + str(self.height) + ' cm high and is ' + str(get_age(self)) + ' years old'
    birthdate = date(1976, 8, 14)
    self = create_self('Michael', 190, birthdate)

You may also like…

amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js