-3
Good morning, someone can help me?
It is intended to develop the function
invert_pal(st)
it takes as parameter a stringst
and returns as a result the same string in which each word was inverted.
For example,invert_pal(“Eu gosto de programar”)
should return the string“uE otsog ed ramargorp”
.
In the resolution of this exercise you must use a stack (can consider the existence of the stack class not needing to develop it).
Lf= []
st= (input ("Introduza a palavra: "))
L= list (st)
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 top(self):
return self.items[len(self.items)-1]
def size(self):
return len(self.items)
def invert_pal ():
inverter= Stack ()
for i in L:
inverter.push(i)
while not inverter.isEmpty():
y= inverter.pop()
Lf.append(y)
print (str(Lf))
a= invert_pal()
print (a)
On the last lines, you display the variable
a
, which is the return ofinvert_pal
, but the function has no return. This doesn’t seem right.– Woss