Question
Can you check what is the mistake in the below code ? I'm getting the error NameError: name 'total_nodes' is not defined ==== def max_degree_nodes(self)->dict:
Can you check what is the mistake in the below code ? I'm getting the error
NameError: name 'total_nodes' is not defined
====
def max_degree_nodes(self)->dict: """ Return the node(s) with the highest degree Return multiple nodes in the event of a tie Format is a dict where the key is the node_id and the value is an integer for the node degree e.g. {'a': 8} or {'a': 22, 'b': 22} """ tot_nodes = total_nodes(self) tot_edges = total_edges(self)
degree_map = {} highest_degree_map = {}
for i in range(tot_edges): degree_map[self.edges[i][0]] = 0 degree_map[self.edges[i][1]] = 0
for i in range(tot_edges): degree_map[self.edges[i][0]] += 1 degree_map[self.edges[i][1]] += 1
high_degree = 0
for i in range(1,tot_nodes+1): high_degree = max(high_degree,degree_map[i])
for i in range(1,tot_nodes+1): if (degree_map[i] == high_degree): highest_degree_map = (degree_map[i][0],i)
return highest_degree_map =====
definition of total_nodes is below
=== def total_nodes(self)->int: """ Returns an integer value for the total number of nodes in the graph """ tot_nodes = len(self.nodes) return tot_nodes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started