好的,所以我正在尝试输入“Hello World!” 我希望输出为“dlroW olleH”我的代码一一打印相反的内容。我该如何解决?
class Stack:
def __init__(self):
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 is_empty(self):
return len(self.__items) == 0
def size(self):
return len(self.__items)
def __len__(self):
return len(self.__items)
x = Stack()
userinput = input("enter ")
for letter in userinput:
x.push(letter)
while x:
print(x.pop())