Question
IN PYTHON The input file friendship.txt, has the data of a group of friends. Each line shows the names of two persons who are friends
IN PYTHON
The input file friendship.txt, has the data of a group of friends. Each line shows the names of two persons who are friends with each other. Your program should work for any input files that fit the file format with a different set of data. Example: Tanvir Annika Annika John Nicole Annika John Tanvir Note: Each pair will only be represented once in the file. So, John Annika and Annika John represent the same friendship and both will not appear in the file. This is called a symmetric relation (you will learn more about this in CISC102 and CISC203). Your Task
1. Write a Python function friends_to_dictionary() that takes no input, and converts the file called friendship.txt into a dictionary, and returns said dictionary.
2. Write a Python function called all_my_friends(friend), that takes as input a friend in the list (you may assume the friend is in the dictionary without testing in the function), and returns a list of all friends who are friends with the given name.
3. Write a Python function called friendship_degree(dictionary) that takes as input the dictionary created above, and writes the number of friends each person has (in any order) along with their names. You may use the previous function if you choose.
Sample output for this function:
John has 2 friends: (Robin, Anna)
Annika has 3 friends: (......)
Nicole has 1 friend: (......)
Tanvir has 2 friends: (......)
Now, use all of your functions in a main program called a2_q2.py (dont forget to import your functions file). You should have this main program initiate the dictionary you create, and then eventually output the friendship degree as described in 3.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started