English

Here is the code for the pop method in the stack to print a string in reverse order. But there is some missing word. Which value will be used in line 7?

Advertisements
Advertisements

Question

Here is the code for the pop method in the stack to print a string in reverse order. But there is some missing word. Answer the question that follows to execute the code successfully.

def popstack (stack)__ # Line 1
if isempty (stack): # Line 2
___ # Line 3
___: #Line 4
top = len(stack) __ # Line 5
for a in range (top, -1, -1):
print stack__, # Line 7
return

Which value will be used in line 7?

Options

  • (A)

  • [a]

  • <a>

  • {a}

MCQ
Advertisements

Solution

[a]

Explanation:

The index position of the list item is represented by [a]. The assertion Print stack[a] will print the stack item starting at index point [a], where a can range from the last index position to 0 to reverse the text.

shaalaa.com
  Is there an error in this question or solution?
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×