#ccm April 2014 # This program keeps track of a group of friends for you. #Here are the functions to be filled in: # Task 1. Prompt user for friend's info and add it to the dictionary # I have done most of it: Your job is to think of one more kind of information to prompt the # user for and add that info to the afriend dictionary. def addAFriend (friends): name = input("What is the name?: ") month = int (input( "What month is the birthday? ")) day = int (input("What day is the birthday? ")) score = int (input("How close is this friend[0=acquaintance, 5=bff] ?: " )) #your code goes here. Note birthday is a tuple. afriend = {"name":name, "birthday":(day, month), "friendship-score": score} friends.append( afriend ) #append it to the friend list return friends # Task 2. Replace the print statment with code to print all the names (names only) in the list of friends. def printFriends(friends): print ("Not implemented") return None # Task 3. Replace the print statement with code to prompt the user for a friendship score [0=acquaintance, 5=bff] # go through the friends list, and and print only the names of friends with higher scores def printCloseFriends(friends): print ("Not implemented") return None # Task 4. Ask user for a friend's name, find the friend in the list, and print all the info associated with that friend, # including keys and values. If the friend is not in the list, apologize and let the user try again. def findFriend (friends) : print("Not implemented") return None # Task 5. Go through the list of friends. Print the name of each friend and invite the user to change the friendship score. # Also invite the user to give a reason (a string) for changing the score. Add a new item -- "memo":reason -- to the entry. # (some friends will have this memo key/value and some won't). def changeFriendshipStatus (friends): print ("Not implemented.") return friends #----- Get a command from user and return it: def getCommandFromUser( options ): while True: print ("Your options are: ") for opt in options: print( "\t", opt, " : " , options[opt].capitalize()+"." ) #tab in, capitalize, add a period cmd = input("Choose an option by letter: ").lower().strip() if cmd in options: return cmd else: print ("I don't understand that option. Try again. ") # ---- Main starts here def main(): commands = { "q":"quit", "p":"print all friends" ,"c":"print close friends", "f":"find a friend by name", "a": "add a friend","c": "change friendship level"} myfriends = [ ] #initially empty = no friends print ("Hi! I will help you keep track of your friends." ) while True: cmd = getCommandFromUser(commands) if cmd =="q": break; elif cmd == "p": printFriends (myfriends) elif cmd == "c": printCloseFriends (myfriends) elif cmd == "f": findFriend (myfriends) elif cmd == "a": myfriends = addAFriend (myfriends) elif cmd == "c": myfriends = changeFriendshipStatus (myfriends) print ("Thanks! That was fun!") main()