Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First, create a python class called ? Person ? that will store the information a

ID: 3904085 • Letter: F

Question

First, create a python class called ?Person? that will store the information about a person. Be sure to store the following attributes:

? first_name? - string

? last_name ?- string

? age ?- integer

? address? - string

? phone_number? - string

? email? - string

? interests - ?a list of strings (each string is a short description of something they

are interested in)

As a part of this class, write an ?__init__?function in your person class that that has a parameter for each class attribute and sets them properly when a new person object is created. Once this is done, write a ?__str__? function that will convert some or all of the attributes in the person class into a string suitable to be printed to the screen. Examples of both of these functions were given in class.

Outside of your class, create a few new person objects and store them in a list. Then write a for loop to iterate over these person objects and print them out.

Outside of your ?Person? class write a function called ?over_age? that takes a list of person objects and an integer as its parameters. This function will iterate over the list of person objects and print out each person that is over the age provided.

Create a function inside your ?Person ?class called a? dd_interest?. This function will take string as its only parameter. This function will add the interest provided to the list of interests within the person object only if it is not already in the list. If the interest is in the list this function will do nothing. ?HINT: ?since you are writing this function in the person class, you will have to use the self? variable to access and change the interests variable, as shown in class.

Create a function inside your ?Person ?class called r? emove_interest?. This function will take string as its only parameter. This function will remove the interest provided from list of interests within the person object only if it is already in the list. If the interest is not in the list this function will do nothing.

Create a function outside of your person class called ?something_in_common?. This function will take two person objects as parameters. It will then compare the interests of the two person objects. The function will return a boolean: it will return ?True? is the two person objects have an interest in common and will return ?False? if they don’t.

Explanation / Answer

class Person:
def __init__(self,firstname,lastname,age,adress,phone,email,interests):
self.firstname=firstname
self.lastname=lastname
self.age=age
self.adress=adress
self.phone=phone
self.email=email
self.interests=interests
def __str__(self):
self.firstname=str(self.firstname)
self.lastname=str(self.lastname)
self.age=str(self.age)
self.adress=str(self.adress)
self.phone=str(self.phone)
self.email=str(self.email)
def dd_interest(self,interest):
flag=False
for i in self.interests:
if(interest==i):
flag=True
if(flag):
print("Alreay intreste existed")
else:
self.interests.append(interest)
print("updated intrests:",self.interests)
def remove_interest(self,interest):
flag=False
for i in range(len(self.interests)):
if(interest==self.interests[i]):
flag=True
del self.interests[i]
print("updated intrests:",self.interests)
if not flag:
print("No interest found to remove")
  
def over_age(persons,age):
for person in persons:
if person.age > age:
print(person.firstname,"overage")
else:
print(person.firstname,"Not overage")
def common(p1,p2):
if p1.firstname==p2.firstname:
return True
elif p1.lastname==p2.lastname:
return True
elif p1.age==p2.age:
return True
elif p1.adress==p2.adress:
return True
elif p1.phone==p2.phone:
return True
elif p1.email==p2.email:
return True
elif p1.interests==p2.interests:
return True
else:
return False
def main():
P1= Person("Ram","Bhagavan",24,"Heaven",8985,"ram@seetha.com",['sleep','study'])
P2=Person("phani","hani",21,"india",9899,"tingaribalu@g.com",['sleep','study'])
persons=[P1,P2]
for i in range(len(persons)):
print("details:",persons[i].firstname,persons[i].lastname,persons[i].age,persons[i].adress,persons[i].phone,persons[i].email,persons[i].interests)
P1.dd_interest('run')
over_age(persons,25)
P1.remove_interest('run')
print(common(P1,P2))
main()