Question
What will be the output of the following code when
printList is called with a linked list containing the values 1 -> 2 -> 3? class Node:   def __init__(self, data):     self.data = data     self.next = None class LinkedList:   def __init__(self):     self.head = None   def append(self, data):     new_node = Node(data)     if not self.head:       self.head = new_node       return     last_node = self.head     while last_node.next:       last_node = last_node.next     last_node.next = new_node   def printList(self):     current = self.head     while current:       print(current.data, end=" -> ")       current = current.next     print("None") ll = LinkedList() ll.append(1) ll.append(2) ll.append(3) ll.printList()Solution
In this code, a linked list is implemented where each Node contains a data field and a reference to the next node. The LinkedList class provides methods to append nodes and print the list. The append method adds nodes to the end of the list, and printList iterates through the list, printing each node's data followed by " -> ". When nodes with values 1, 2, and 3 are appended, the list becomes 1 -> 2 -> 3, and printList outputs 1 -> 2 -> 3 -> None. Why Other Options Are Wrong: B) 1 -> None: This option is incorrect because it implies that only 1 is in the list, ignoring the 2 and 3 that were appended. C) 2 -> 3 -> None: This option is incorrect because it suggests that the list starts with 2, which is not true since 1 was added first. D) 3 -> 2 -> 1 -> None: This option is incorrect as it represents a reverse order of the list, which does not occur when appending in the given code. E) None: This option is incorrect as it implies there is no output or that the list is empty, which is not the case.
The first shirt is sold at twice the selling price of the second shirt. The first shirt is sold at 8% profit and the second shirt is sold at a 3% loss. ...
'C' sells a laptop at a profit of 50%. Had the profit percentage earned on selling the laptop been numerically equal to the cost price of the laptop, th...
An item costs ₹2,000 less than ₹5,000. The dealer offers a discount of 10% and the retailer further offers a discount of 5% on its CP. The final SP ...
A man sold 30 articles for ₹100 and gained 20%. The number of articles he bought for ₹100 was:
The cost price of an article is Rs. 2335 and a shopkeeper wants to earn 12% profit on it after giving 20% discount on marked price. Find the marked pric...
A seller marked the price of an item at Rs. 6,000. The seller gave successive discounts of (c + 6)% and (c - 6)% to a customer. If the customer paid Rs....
Mohit sold 5 pens making a 8% profit on each and another 15 pens making a 12% profit on each. If the total selling price for all 20 pens was ₹555, wha...
The sale price of an item is set at 30% above the cost price. After giving a 10% discount on the marked price, what is the merchant’s profit percentag...
Ajay bought a Sopha for Rs. 81000. After one year he sold it to Vikas at 20% less of his cost price. Vikas spends extra Rs. 750 for its repair. A...
The cost price of an article is Rs. 2500 and a shopkeeper wants to earn 12% profit on it after giving 20% discount on marked price. Find the marked pric...