Business Analyst/Power BI Developer
Hometown: Bantayan Island
Current City: Lapu-Lapu City
Phone: +639565028805
Email: cirobar@outlook.com
LinkedIn: Cyrus Baruc
My CV: Click To Download
You are given the simple class called Name
. Modify the cell below to make the Name
class more useful
__init__()
method for Name
. This function must accept 3 parameters. Inside the __init__()
method create three attributes: the first parameter must be assigned to the attribute first
, the second parameter must be assigned to the attribute middle
and the third paramter to the attribute last
fullName()
. This returns the full name in the following format {first} {middle initial}. {last}
Example: Rubelito R. Abella
fullNameLastFirst()
. This returns the full name in the following format {last}, {first} {middle}.
Example: Abella, Rubelito Reboquio
class Name:
def __init__(self):
self.first = "Cyrus"
self.middle = "Cueva"
self.last = "Baruc"
def fullName(self):
return f"{self.first} {self.middle[0]}. {self.last}"
def fullNameLastFirst(self):
return f"{self.last}, {self.first}, {self.middle}"
When the Name
function is complete, create a new class with the following instruction:
TitledName
. This class should inherit from Name
.__init__()
class. Instead of accepting 4 parameters, this method accepts 4. The fourth parameter must be assigned to the attribute ‘title’.titledFullName()
This returns the full name in the following format {title} {first} {middle initial}. {last}
Example: Mr. Rubelito R. Abella
#Your code here
class TitledName(Name):
def __init__(self):
self.first = "Cyrus"
self.middle = "Cueva"
self.last = "Baruc"
self.title = "Mr."
def titledFullName(self):
return f"{self.title} {self.first} {self.middle[0]}. {self.last}"
cl = TitledName()
cl.fullName()
'Cyrus C. Baruc'
cl.fullNameLastFirst()
'Baruc, Cyrus, Cueva'
cl.titledFullName()
'Mr. Cyrus C. Baruc'