Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The language is Python: Here is the code to turn the file into a list in python: def read_family(filename): family = [] f = open(filename,

The language is Python:

image text in transcribed

Here is the code to turn the file into a list in python:

def read_family(filename): family = [] f = open(filename, "r") for line in f: entry = line.strip().split(",") for i in range(3): entry[i] = entry[i].strip() if entry[i] == '': entry[i] = None family += [entry] return family

This is the family file just copy and paste it into a txt file name hobbits and the code on top should work:

Buffo Boffin,, Ivy Goodenough,, Madoc Brandybuck, Gormadoc Brandybuck, Malva Headstrong Sadoc Brandybuck, Gormadoc Brandybuck, Malva Headstrong Marmadoc Brandybuck, Madoc Brandybuck, Hanna Goldworthy Salvia Brandybuck, Sadoc Brandybuck, Theobald Bolger, Gundabald Bolger, Salvia Brandybuck Wilibald Bolger, Theobald Bolger, Nina Lightfoot Wilimar Bolger, Wilibald Bolger, Prisca Baggins Heribald Bolger, Wilibald Bolger, Prisca Baggins Nora Bolger, Wilibald Bolger, Prisca Baggins Gundolpho Bolger,, Alfrida of the Yale,, Gundahad Bolger, Gundolpho Bolger, Alfrida of the Yale Gundabald Bolger, Gundahad Bolger, Rudolph Bolger, Gundolpho Bolger, Alfrida of the Yale Gundahar Bolger, Gundolpho Bolger, Alfrida of the Yale Fastolph Bolger, Rudolph Bolger, Cora Goodbody Adaldrida Bolger, Gundahar Bolger, Dina Diggle Gorbadoc Brandybuck, Marmadoc Brandybuck, Adaldrida Bolger Adalgar Bolger, Gundahar Bolger, Dina Diggle Ruby Bolger, Adalgar Bolger, Rudigar Bolger, Adalgar Bolger, Rudibert Bolger, Adalgar Bolger, Bosco Boffin, Buffo Boffin, Ivy Goodenough Basso Boffin, Buffo Boffin, Ivy Goodenough Briffo Boffin, Buffo Boffin, Ivy Goodenough Berylla Boffin, Buffo Boffin, Ivy Goodenough Otto Boffin, Bosco Boffin, Hugo Boffin, Otto Boffin, Lavender Grubb Ponto Baggins I, Balbo Baggins, Berylla Boffin Mungo Baggins, Balbo Baggins, Berylla Boffin Largo Baggins, Balbo Baggins, Berylla Boffin Pansy Baggins, Balbo Baggins, Berylla Boffin Lily Baggins, Balbo Baggins, Berylla Boffin Polo Baggins, Ponto Baggins I, Mimosa Bunce Rosa Baggins, Ponto Baggins I, Mimosa Bunce Bungo Baggins, Mungo Baggins, Laura Grubb Belba Baggins, Mungo Baggins, Laura Grubb Longo Baggins, Mungo Baggins, Laura Grubb Linda Baggins, Mungo Baggins, Laura Grubb Bilbo Baggins, Bungo Baggins, Belladonna Took Fosco Baggins, Largo Baggins, Tanta Hornblower Isengrim Took II,, Isumbras Took III, Isengrim Took II, Ferumbras Took II, Isumbras Took III, Bandobras Took, Isumbras Took III, Fortinbras Took I, Ferumbras Took II, Gerontius Took, Fortinbras Took I, Isengrim Took III, Gerontius Took, Adamanta Chubb Hildigard Took, Gerontius Took, Adamanta Chubb Isumbras Took IV, Gerontius Took, Adamanta Chubb Isembold Took, Gerontius Took, Adamanta Chubb Hildifons Took, Gerontius Took, Adamanta Chubb Isembard Took, Gerontius Took, Adamanta Chubb Hildibrand Took, Gerontius Took, Adamanta Chubb Donnamira Took, Gerontius Took, Adamanta Chubb Hildigrim Took, Gerontius Took, Adamanta Chubb Belladonna Took, Gerontius Took, Adamanta Chubb Mirabella Took, Gerontius Took, Adamanta Chubb Fortinbras Took II, Isumbras Took IV, Ferumbras Took III, Fortinbras Took II, Lalia Clayhanger Flambard Took, Isembard Took, Adelard Took, Flambard Took, Everard Took, Adelard Took, Reginard Took, Adelard Took, Sigismond Took, Hildibrand Took, Rosamunda Took, Sigismond Took, Jessamine Boffin, Hugo Boffin, Donnamira Took Herugar Bolger, Rudigar Bolger, Belba Baggins Odovacar Bolger, Herugar Bolger, Jessamine Boffin Fredegar Bolger, Odovacar Bolger, Rosamunda Took Estella Bolger, Odovacar Bolger, Rosamunda Took Posco Baggins, Polo Baggins, Asphodel Brandybuck, Gorbadoc Brandybuck, Mirabella Took Rorimac Brandybuck, Gorbadoc Brandybuck, Mirabella Took Amaranth Brandybuck, Gorbadoc Brandybuck, Mirabella Took Saradas Brandybuck, Gorbadoc Brandybuck, Mirabella Took Dodinas Brandybuck, Gorbadoc Brandybuck, Mirabella Took Dinodas Brandybuck, Gorbadoc Brandybuck, Mirabella Took Primula Brandybuck, Gorbadoc Brandybuck, Mirabella Took Porto Baggins, Posco Baggins, Gilly Brownlock Ponto Baggins II, Posco Baggins, Gilly Brownlock Peony Baggins, Posco Baggins, Gilly Brownlock Milo Burrows, Rufus Burrows, Asphodel Brandybuck Moro Burrows, Milo Burrows, Peony Baggins Myrtle Burrows, Milo Burrows, Peony Baggins Minto Burrows, Milo Burrows, Peony Baggins Mosco Burrows, Milo Burrows, Peony Baggins Adalgrim Took, Hildigrim Took, Rosa Baggins Paladin Took II, Adalgrim Took, Esmeralda Took, Adalgrim Took, Pimpernel Took, Paladin Took II, Eglantine Banks Pervinca Took, Paladin Took II, Eglantine Banks Peregrin Took I, Paladin Took II, Eglantine Banks Pearl Took, Paladin Took II, Eglantine Banks Faramir Took I, Peregrin Took I, Diamond Took Saradoc Brandybuck, Rorimac Brandybuck, Menegilda Goold Merimac Brandybuck, Rorimac Brandybuck, Menegilda Goold Meriadoc Brandybuck, Saradoc Brandybuck, Esmeralda Took Berilac Brandybuck, Merimac Brandybuck, Seredic Brandybuck, Saradas Brandybuck, Doderic Brandybuck, Seredic Brandybuck, Hilda Bracegirdle Ilberic Brandybuck, Seredic Brandybuck, Hilda Bracegirdle Celandine Brandybuck, Seredic Brandybuck, Hilda Bracegirdle Drogo Baggins, Fosco Baggins, Ruby Bolger Dora Baggins, Fosco Baggins, Ruby Bolger Dudo Baggins, Fosco Baggins, Ruby Bolger Frodo Baggins, Drogo Baggins, Primula Brandybuck Daisy Baggins, Dudo Baggins, Tosto Boffin, Griffo Boffin, Daisy Baggins Adalbert Bolger, Rudibert Bolger, Amethyst Hornblower Filibert Bolger, Adalbert Bolger, Gerda Boffin Otho Sackville-Baggins, Longo Baggins, Camellia Sackville Lobelia Sackville-Baggins, Longo Baggins, Camellia Sackville Lotho Sackville-Baggins, Otho Sackville-Baggins, Lobelia Sackville-Baggins Odo Proudfoot, Bodo Proudfoot, Linda Baggins Olo Proudfoot, Odo Proudfoot, Sancho Proudfoot, Olo Proudfoot,
from a family tree database. Task A: Direct Ancestor (6 Marks) Implement a function direct ancestor (p1, p2, family) with the following specification. Input: Two strings representing two names, p1 and p2, and a family tree database family. Output: One of the following three string outputs as appropriate (where pi and p2 are the given input strings, and n is a string representation of a non-negative integer): "pi is a direct ancestor of p2, n generations apart." "p2 is a direct ancestor of p1, n generations apart." "p1 is not a direct ancestor or descendant of p2." For example, direct ancestor (p1, p2, family) should behave as follows: >>> hobbits = read_family('hobbit-family.txt') >>> direct_ancestor ('Frodo Baggins', 'Frodo Baggins', hobbits) 'Frodo Baggins is a direct ancestor of Frodo Baggins, o generations apart.' >>> direct_ancestor ('Frodo Baggins', 'Gormadoc Brandybuck', hobbits) 'Gormadoc Brandybuck is a direct ancestor of Frodo Baggins, 5 generations apart

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

(1) What is your current leadership development strategy?

Answered: 1 week ago