Menu

[Solved]-Python Background Imagine Creating New Social Network Assignment Write Person Class Model Q37240673

python:BackgroundImagine you are creating a new social network. For thisassignment, you will write a Person class to model a member of thesocial network. A Person object has a name and a set ofconnections. Connections are symmetrical: when one person hasanother person as a connection, the other person also has the firstperson as a connection.InstructionsUpload an original Python module that contains a class calledPerson.A Person object should have the following twoattributes:name (a string, such as “John” or “Heather”)connections (a set of Person objects to whom the person isconnected; initially, this will be an empty set)A Person object should have three methods:__init__() initializes a new Person object. It takes oneargument, a name which should be the value of the nameattribute. Itshould initialize the connections attribute to an empty set.add_connection() takes one argument, another Person object; ifthat object is not already in connections, it adds the object andcalls that object’s add_connection() method.get_second_connections() takes no arguments and returns theset of Person objects that are not self and are are not connectionsof self.Your code should follow the style guide, including script,class, and method docstrings, and an if __name__ ==’__main__’:statement if you wish to execute any code in yourscript. (If you do not make any function calls at the global levelof your script, you can omit if __name__ == ‘__main__’:).TestingThe following diagram illustrates one possible example of asocial network:
Emily Christopher MichaelJ JacobAshley Jessica Matthew SarahThe following code should create the network pictured above.It is assumed that this code is in the same directory as yourscript. You should replace yourscript with the name of your script(without the .py extension).from yourscript import Person
michael = Person(“Michael”)emily = Person(“Emily”)jessica = Person(“Jessica”)jacob = Person(“Jacob”)christopher = Person(“Christopher”)ashley = Person(“Ashley”)matthew = Person(“Matthew”)sarah = Person(“Sarah”)
michael.add_connection(emily)michael.add_connection(jacob)michael.add_connection(christopher)michael.add_connection(jessica)emily.add_connection(christopher)christopher.add_connection(ashley)jacob.add_connection(ashley)jacob.add_connection(matthew)jessica.add_connection(matthew)ashley.add_connection(sarah)For this network, Michael’s secondconnections are Emily, Christopher, Jacob and Jessica Ashley andMatthew (thanks to those who pointed out my mistake!). (You cancheck this by printing the name attribute of each person returnedby michael.get_second_connections().Emily Christopher MichaelJ JacobAshley Jessica Matthew Sarah Show transcribed image text Emily Christopher MichaelJ JacobAshley Jessica Matthew Sarah

Expert Answer


Answer to python:BackgroundImagine you are creating a new social network. For this assignment, you will write a Person class to … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *