Computer Science

Find the output of the following code:

result = 0
numberList = [10, 20, 30]
numberList.append(40)
result = result + numberList.pop()
result = result + numberList.pop()
print("Result=", result)

Python Stack

8 Likes

Answer

Output
Result= 70
Explanation

The code initializes result to 0 and creates a list [10, 20, 30]. It appends 40 to the list and then performs two pop() operations on the list, which removes and returns the last element (40 and 30). These values are added to result, resulting in result being 70. Finally, the code prints "Result=" followed by the value of result, which is 70.

Answered By

1 Like


Related Questions