0
Palindrome stack
https://code.sololearn.com/cNRe0HmTzL2n/?ref=app What is my error ? The output should be true ... And should work with .pop by how to become the result ?
12 Respostas
+ 2
You're using python,
You can use stringname[::-1] to get whole string in reverse, why do you need to reverse it manually?
simple solution is to compare text with text[::-1]
def is_palindrome_stack(text):
#Returns True if wird is a palindrome
if text == text[::-1]:
print (True)
else:
print (False)
is_palindrome_stack('regallager')# True
is_palindrome_stack('reliefpfeiler')#True
+ 2
def is_palidrom(text) :
arr = []
for c in text:
arr. append(c)
for c in text:
if c !=arr.pop():
return False
return True
0
i need to do revetse it mannually because ir is my task 😒
0
maybe you have a trick for me?
0
First, you can inside of function make print of variable and you'll see - they are different.
Short version, anyway :
def is_palidrom(text) :
return text == text[::-1]
It will return True or False.
0
but can i build the append and pop function to check the solution ?
0
Sara. P you can.
Can you say what is exactly your task?
0
Write a function is_palindrome_stack (text) checks if the entered text is a palindrome. Use the solution for the stack function use (append / pop)
0
i though about a for loop...? but i cant write a code 🤯
0
thank you it works 😃
0
thank you it works 😃
0
You are welcome)