Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON The parents dictionary in the final.py file is a dictionary whose keys ar

ID: 3858681 • Letter: P

Question

PYTHON

The parents dictionary in the final.py file is a dictionary whose keys are strings (names) and whose values are lists of strings (names). For example:

>>> parents['Mark Zuckerberg']

['Edward Zuckerberg', 'Karen Zuckerberg']
The parents of Mark Zuckerberg (the CEO of Facebook) are named Edward Zuckerberg and Karen Zuckerberg.

Complete the ancestors function, so that it returns a list of the ancestors of a person, including the person's parents, grandparents, great grandparents, and so on (assuming those ancestors are listed in the dictionary). Although the parents dictionary as it stands only goes back as far as two of Mark's great grandparents, you should assume that the ancestry information of a person might continue for an arbitrary number of generations.

When completed, here are some of examples of correct output:

>>> ancestors('Mark Zuckerberg')

['Edward Zuckerberg', 'Karen Zuckerberg', 'Miriam Hollnder', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg'] >>> ancestors('Edward Zuckerberg')

['Miriam Hollnder', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg']

>>> ancestors('Jack Zuckerberg')

['Minnie Wiesenthal', 'Max Zuckerberg']

THIS CODE WAS GIVEN TO FOR US IN ORDER TO COMPLETE THE QUESTION ABOVE:

from urllib.request import urlopen
from html.parser import HTMLParser
from tkinter import *
from random import randint

parents = dict()
parents['Mark Zuckerberg'] = ['Edward Zuckerberg', 'Karen Zuckerberg']
parents['Edward Zuckerberg'] = ['Miriam Holländer', 'Jack Zuckerberg']
parents['Jack Zuckerberg'] = ['Minnie Wiesenthal', 'Max Zuckerberg']

def ancestors(person):
# base case
if parents.get(person) == None:
# you should return something here
pass
# recursive case
else:   
ancs = parents.get(person)
# fill in the rest

# return something at the end

Explanation / Answer

def ancestors(person):
# base case
if parents.get(person) == None:
print " nob records found"
pass
# recursive case
else:   
ancs = parents.get(person)
ansectors(ancs)

return ancs

# return something at the end