We'll be storing a group of friends, and then allowing rerieval of information about them in a few ways.
In class Friend, each friend instance should store a name, a color (favorite color) and a category (an integer between 1 and 4 indicating some personal feature of your friend).
class FriendGroup has the methods to digest and retrieve Friends. You need to store the Friend instances in a dictionary in this class, with the key = name. Methods should include the following:
add(name, color, category) # adds a new friend or replaces fields of an existing friend.
delete(name) # delete a friend if found. Returns True if successfully deleted, else False.
change_cat(old_category,new_category) changes the category of those Friends with old_category, giving each a brand new_category. Returns the number of changes made.
class Friend: def __init__(self,name,color,category): # your excellent code here to store name and category class FriendGroup: def __init__(self): # your more excellent code here to create a FriendGroup def add(self,name,color,category): # more def delete(self,name): # even more def get_cat(name): # less def change_cat(self,old_category,new_category): # more or less def get_friend(self,name): # less is more def get_names(self): # all of them
Here are the commands that do not write to the ouptut file, with code examples:
This command will write, to the output file, the name of each friend and her favorite color and category -- one per line, in alphabetical order.
Output will look like: