Question 2 of 7intermediate🔧 ApplyShort Answer4 marks
Find the output of the following code:
(a)
result=0 numberList=[10,20,30] numberList.append(40) result=result+numberList.pop() result=result+numberList.pop() print("Result=",result)
Answer
Result= 70
(b)
answer=[]; output=" answer.append('T') answer.append('A') answer.append('M') ch=answer.pop() output=output+ch ch=answer.pop() output=output+ch ch=answer.pop() output=output+ch print("Result=",output)
Answer
Result= MAT
Explanation
This question tests understanding of stack operations using Python lists. The append() method adds elements to the top of the stack, while pop() removes and returns the last element following the LIFO (Last In First Out) principle.