0

I was stuck in this question. I have done most of the parts but the last part in which we were supposed to compare it, I was stuck in that part could help me up with this in python.
A class called Actor is designed to model a movie’s actor. It contains three instance variables: name (String), dateofBirth (String), and gender (char of either 'm' or 'f').

The requirements for this class arre:

  • There should be getter and setter function for all instance variables.
  • Actor also performs in movies so make a list of the movie for each actor and store the names of the movie in it.
  • There should be methods DisplayActor which displays all the actor data along with the movies.
  • For an actor, add AddMovie function which adds movie name in the list.
  • Add one more function named CompareActor that compares the two objects of actor class and find if they have worked together in the same movie.
  • This function will return the list of the same movies.

I have attached my code below.

class Actor:
    def __init__(self,name,dateofBirth,gender):
       self._name = name
        self._dateofBirth = dateofBirth
        self._gender = gender
        self._movies = []
    def set_name(self,name):
        self._name = name
    def set_dateofBirth(self,dateofBirth):
        self._dateofBirth= dateofBirth 
    def set_gender(self,gender):
      self._gender = gender 
    def get_name(self):
       return self._name
    def get_dateofBirth(self):
       return self._dateofBirth
    def get_gender(self):
            return self._gender
    def addmovies(self,movies):
        self._movies.append(movies)
    def DisplayActor(self):
        print("Name of Actor=",str(self._name),"DOB=",str(self._dateofBirth),"Gender=",str(self._gender),"Movies=",str(self._movies))
    
def main():
  act1 = Actor("Fallon","22 january","m")
  act1.addmovies("Deadpool")
  act1.addmovies("Avengers")
  act1.addmovies("Hell Boy")
  act1.DisplayActor()
    
  act2 = Actor("John","3 January","m")
  act2.addmovies("Hell boy")
  act2.addmovies("The Bons Collections")
  act2.addmovies("Nemo")
  act2.DisplayActor()
        
    main()
demokritos
  • 1,416
  • 2
  • 12
  • 34
  • 1
    Hello there, welcome to Stackoverflow. To get most of the community help, I first suggest you to reedit your post in a manner that allow better understanding of your issue. For example, write a code of your attempt, so other might debug it and provide you a hint. Also care about punctuation marks and English writing. – Fabio Mendes Soares Jan 10 '21 at 16:50
  • 1
    Thank you so much for the tips.I have attached my attempt above – PYTHON User Jan 10 '21 at 18:44
  • 1
    Great! I see only the method you've mentioned is missing, namely compareActor. I suppose this method must have two arguments, self and the second actor. To find which movies they acted together, I guess you should iterate over the one actor's list of movies and compare if any is contained in the list of another. Try it out – Fabio Mendes Soares Jan 10 '21 at 19:07
  • This [question](https://stackoverflow.com/q/1388818/6682517) is about comparing two lists in python (lists of movies in your case) and it has several working answers – Sergey Shubin Jan 11 '21 at 08:03

0 Answers0