Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do the task B correctly in PYTHON which is cousin degree as the screenshots above!!! We represent each entry in a family tree database

image text in transcribed

image text in transcribed

Please do the task B correctly in PYTHON which is cousin degree as the screenshots above!!!

We represent each entry in a family tree database as a list of three strings [name, father, mother], where name is a persons name, father is the name of their father, and mother is the name of their mother. Where a particular relationship is unknown, the value None is used.

Hobbit-family.txt is attached as below:

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,

Task B: Cousin Degree (6 Marks) Implement a function cousin_degree(p1, p2, family) with the following specification. Input: Two strings representing two names, p1 and p2, and a family tree database family. Output: An integer representing the minimum distance cousin relationship between pi and p2, as follows: 0, if p1 and p2 are siblings: 1, if p1 and p2 are cousins; some positive integer n, if p1 and p2 are nth cousins, or .-1 if p1 and p2 have no cousin or sibling relationship. For example, cousin_degree (p1, p2, family) should behave as follows: >>> hobbits = read_family("hobbit-family.txt") >>> cousin_degree('Minto Burrows', 'Myrtle Burrows', hobbits) 0 >>> cousin_degree('Estella Bolger', 'Meriadoc Brandybuck', hobbits) 3 >>> cousin_degree('Frodo Baggins', 'Bilbo Baggins', hobbits) -1 def read_family(filename) : 111111 Input: A filename (filename) containing a family tree database where each line is in the form name, father, mother Output: A family tree database containing the contents of the file in the format specified above. For example: >>> hobbits = read_family('hobbit-family.txt') >>> len (hobbits) 119 >>> hobbits [118] ['Sancho Proudfoot', 'olo Proudfoot', None] IT TTT 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

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_2

Step: 3

blur-text-image_3

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions