Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
2.7k views
in Computer by (72.4k points)

Aastha wants to create a program that accepts a string and display the characters in the reverse in the same line using a Stack. She has created the following code,help her by completing the definitions on the basis of requirements given below:

Class mystack :

def inin (self):

selfe. mystr= # Accept a string

self.mylist= # Convert mystr to a list

# Write code to display while removing element from the stack.

def display (self) :

:

:

1 Answer

+1 vote
by (89.5k points)
selected by
 
Best answer

class mystack :

def _init_ (self) :

self.myster= rawjnput ("Enter the string”)

self.mylist = list (self.mystr)

def display (self) :

x = len (self. mylist)

if (x > 0) :

for i in range (x) :

print self.mylist.pop (),

else :

print "Stack is empty”

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...