TORONTO KIDS COMPUTER CLUB | PMCA Saturday 18:30 Python Homework 21.07.10.
post-template-default,single,single-post,postid-19704,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

PMCA Saturday 18:30 Python Homework 21.07.10.

13 Jul PMCA Saturday 18:30 Python Homework 21.07.10.


Input a string. Using a stack, reverse the string and print it.

Sample Input 1:
Enter String to reverse : Apple

Sample Output  1

Sample Input 2

Sample Output 2

Below is the stack class, please use it to reverse the string

class Stack:
    # we are using a list to create a stack
    # so when we create a new stack object, we will start
    # with empty list
    def __init__(self):
        self.s = []

    def push(self,item):
        # use the list method to put the item into the list

    def pop(self):
    	# get the item at the top
    	# print that item
    	# delete that from that index in the
    	return self.s.pop()

    def peek(self):
    	# print the item at the top of the stack
    	# do not delete it
    	return self.s[-1]

    def isEmpty(self):
    	# check if the stack is empty
    	return len(self.s) == 0

    def size(self):
    	# print the size of the stack
    	return len(self.s)

No Comments

Sorry, the comment form is closed at this time.