2 2 votes Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None n1 = Node(5) n2 = Node(10) n3 = Node(15) n4 = Node(20) n1.next = n2 n2.next = n3 n3.next = n4 t = n1 count = 0 total = 0 while t is not None: count = count + 1 total = total + t.data t = t.next print(count, total)What is the output of the code above?3 304 504 455 50 Programming in Python goclasses goclasses-da-dpp goclasses-da-dpp-day-211 programming-in-python goclasses-python-&-dsa-practice-questions output linked-list + – GO Classes 115 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes The linked list is:5 -> 10 -> 15 -> 20 -> NoneThe variable $\texttt{t}$ starts from $\texttt{n1}$.The loop runs while $\texttt{t is not None}$. In each iteration:count = count + 1 total = total + t.data t = t.nextStep-by-step traversal:Node 1: data = 5, count = 1, total = 5 Node 2: data = 10, count = 2, total = 15 Node 3: data = 15, count = 3, total = 30 Node 4: data = 20, count = 4, total = 50After node $4$, $\texttt{t}$ becomes $\texttt{None}$, so the loop stops.Therefore, the output is:4 50Correct Option: B GO Classes answered Jun 29 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.