Question: PYTHON Programming Given Code: user.py (below) class SocialNetworkUser: # create array called friends friends = [] # Define __init__ method. def __init__(self, screen_name, birth_date, relationship_status,

PYTHON Programming

Given Code: user.py (below)

class SocialNetworkUser: # create array called friends friends = [] # Define __init__ method. def __init__(self, screen_name, birth_date, relationship_status, phone_number): self.screen_name = screen_name self.birth_date = birth_date self.relationship_status = relationship_status self.phone_number = phone_number # Define __str__ method. def __str__(self): return "%s | %s | %s | %s" % (self.screen_name, self.birth_date, self.relationship_status, self.phone_number) # Define add_friend method. def add_friend(self, the_friend): self.friends.append(the_friend)

Given Code: test1.py (below)

from user import SocialNetworkUser

# create first user snu1 = SocialNetworkUser("Simi Maurya", "08-28-1996", "Single", "6125678798") print(snu1)

# add friends to specific user snu1.add_friend("PonyTail") snu1.add_friend("Applejacks") for friend in snu1.friends: print(friend, end = ' ') print( )

Deliverables: socialnetworkuser.py, test2.py, test3.py

Goal:

(1) Convert the traditional test file (test1.py) to a unit test file called test2.py

(2) Write a script, test3.py that allows the user to input a screen name at the keyboard. The script will then output the profile of that object and the profiles of all its friends.

- Create an array of SocialNetworkUser objects called arr using profile data from users.txt (listed below)

- Add friends to the SocialNetworkUser objects in the array using the screennames in friends.txt (listed below). The lines in users.txt and friends.txt match exactly. For example Line 7 in users.txt contains the profile for screen name JitterBug; Line 7 in friends.txt contains the friends of JitterBug: Whopper,ShinkyDink. Lines 4 and 15 are empty, which means that the SocialNetworkUser object defined by lines 4 and 15 in users.txt: JawBreaker and Lollipop, have no friends.

Note: you will work with two input file objects. Here is pseudocode for adding friends to the array of SocialNetworkUser objects:

open input file friends.txt, call the file object fin read and throw away header line line_number = 0 for each remaining line in file fin use line.split to obtain list of friends for each f in friends append f to arr[line_number].friends end line_number += 1 end

- Prompt the user to enter a screen name, something like this:

desired_screen_name = input("Enter screen name: ") 

Then search the array for the SocialNetworkUser with that screen name and display the profile for that screen name. Also for each friend of that user, search the array for that friend's screen name and display the profile of each friend.

You can use this pseudocode:

input desired screen name for each snu in arr if desired screen name equals screen name of snu print snu for each f in snu.friends for each user in arr if f == user.screen_name print user end end end end end

- Write a standalone method named find_user that inputs a screen name, searches the array, and returns the SocialNetworkUser object with that screen name. Use this find_user method to simplify your script for Part 3. Here is the header for find_user:

def find_user(users, the_screen_name)

users.txt data (below)

screen_name,birthdate,relationship_status,phone_number BuckShot,4/17,Single,222/222-2222 TunaFish,11/5,Married,333/333-3333 JawBreaker,1/8,In a Relationship,444/444-4444 ChatterBox,9/6,Separated,555/555-5555 AppleJacks,7/31,Single,666/666-6666 JitterBug,8/14,Engaged,777/777-7777 OldTimer,10/10,Single,888/888-8888 JiffyGirl,10/30,Married,999/999-9999 Whopper,5/11,It's Complicated,222/333/4444 SquirrelNuts,7/19,Not Specified,333/444/5555 ShrinkyDink,12/25,Single,444/555/6666 Boomerang,11/29,Married,555/666/7777 BrainyBoy,9/8,In a relationship,666/777/8888 Lollipop,6/27,Single,777/888/9999 PonyTail,11/10,Engaged,234/345/4567 Dimples,4/1,Not Specified,345/456/5678 Cupcake,5.20,Engaged,456/567/6789

friends.txt (below)

# Friend screennames of SocialNetworkUsers JawBreaker,JiffyGirl,PonyTail Whopper PonyTail,Dimples,Lollipop,Boomerang Dimples Whopper,ShrinkyDink Whopper BrainyBoy JawBreaker,JiffyGirl,PonyTail PonyTail,Dimples,Lollipop,Boomerang PonyTail,Dimples,Boomerang Cupcake,OldTimer,AppleJacks ChatterBox BuckShot,TunaFish,JawBreaker ChatterBox,JitterBug,AppleJacks BrainyBoy,PonyTail,JiffyGirl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!