Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Reversing a string

$
0
0
class Stack:
     def __init__(self):
          self.items=[]
          
     def isEmpty(self):
         return self.items==[]

     def push(self,item):
         self.items.append(item)

     def pop(self):
         return self.items.pop()

     def peek(self):
         return self.items[len(self.items)-1]

     def size(self):
         return len(self.items)
    
s=Stack()
line=input("Enter a string:")
print(line[::-1])
s.push(line)
print(s.pop())



I want this code to reverse the string:

Enter a string:how are you?
uoy era woh

How come its poping it out in order:
woh era uoy??

I figured it out, need to assign a new variable

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>