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

Help me with python question. There is a template that is already made, and you

ID: 3775822 • Letter: H

Question

Help me with python question.

There is a template that is already made, and you must complete it.

Also, it shows what the outputs look like:

Please make sure your code works in the .py file.

I will copy and paste the template in the bottom, so that you can paste it to your py file.

Copy below and paste it to your py file:

-----------------------------------------------------------------------------------------------------

from random import randint
from tkinter import *
from tkinter.messagebox import showinfo
from urllib.request import urlopen
from urllib.parse import urljoin
from html.parser import HTMLParser
from copy import copy

       
# Coding problem 2: The ancestors function below should
# return a list of ancestors of a person. The list
# is constructed by looking up a person's parents
# in the "parents" dictionary, and then looking up
# those people's parents, etc.

# For example:

# >>> ancestors('Mark Zuckerberg')
# ['Edward Zuckerberg', 'Karen Zuckerberg', 'Miriam Holländer', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg']

# >>> ancestors('Edward Zuckerberg')
# ['Miriam Holländer', 'Jack Zuckerberg', 'Minnie Wiesenthal', 'Max Zuckerberg']

# >>> ancestors('Jack Zuckerberg')
# ['Minnie Wiesenthal', 'Max Zuckerberg']

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):
     answer = copy(parents.get(person)) # the copy function copies a list
     # fill in the rest

from random Import rand int from tkinter import * from tkinter. messagebox import show info from urllib. request import urlopen from urll i b. parse import urljoin from html,parser import HTMLParser from copy import copy on r he e SPns 0-1 r tloa rriP or u-P Pry PrM tmtUT itul rl ot d Xprt 0mor abiPoy emPP tt atin tgtino tras S-1 C rosee OPsusrt Pneqrer nineaso -rPrP rr --am meebbP ottii dllllly an kill t o all r rto rttuuhc

Explanation / Answer

/* structure of a stack node */
struct sNode
;

/* perform to push Associate in Nursing item to stack*/
void push(struct sNode** top_ref, int new_data);

/* perform to pop Associate in Nursing item from stack*/
int pop(struct sNode** top_ref);

/* Returns one if character1 and character2 square measure matching left
and right Parenthesis */
bool isMatchingPair(char character1, char character2)
')
return 1;
else if (character1 == '[' && character2 == ']')
return 1;
else
return 0;
}

/*Return one if expression has balanced Parenthesis */
bool areParenthesisBalanced(char exp[])
{
int i = 0;

/* Declare Associate in Nursing empty character stack */
struct sNode *stack = NULL;

/* Traverse the given expression to envision matching parenthesis */
whereas (exp[i])
may be a beginning parenthesis then push it*/
if (exp[i] == 'may be a ending parenthesis then pop from stack and
check if the popped parenthesis could be a matching pair*/
if (exp[i] == '}' || exp[i] == ')' || exp[i] == ']')
we have a tendency to see Associate in Nursing ending parenthesis while not a combine then come false*/
if (stack == NULL)
return 0;

/* Pop the highest part from stack, if it's not a combine
parenthesis of character then there's a pair.
This happens for expressions like ) */
else if ( !isMatchingPair(pop(&stack), exp[i]) )
return 0;
}
i++;
}

/* If there's one thing left in expression then there's a beginning
parenthesis while not a closing parenthesis */
if (stack == NULL)
come 1; /*balanced*/
else
come 0; /*not balanced*/
}

/* UTILITY FUNCTIONS */
/*driver program to check on top of functions*/
int main()

if (areParenthesisBalanced(exp))
printf(" Balanced ");
else
printf(" Not Balanced ");
return 0;
}

/* perform to push Associate in Nursing item to stack*/
void push(struct sNode** top_ref, int new_data)
assign node */
struct sNode* new_node =
(struct sNode*) malloc(sizeof(struct sNode));

if (new_node == NULL)


/* place within the information */
new_node->data = new_data;

/* link the recent list off the new node */
new_node->next = (*top_ref);

/* move the top to purpose to the new node */
(*top_ref) = new_node;
}

/* perform to pop Associate in Nursing item from stack*/
int pop(struct sNode** top_ref)
{
char res;
struct sNode *top;

/*If stack is empty then error */
if (*top_ref == NULL)

else
high = *top_ref;
res = top->data;
*top_ref = top->next;
free(top);
come res;
}
}