Help with Python - Palindromes - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with Python - Palindromes (/thread-33176.html) |
Help with Python - Palindromes - SantiagoPB - Apr-04-2021 Hello everyone, I have a problem with getting the result of my program . This is a task on palindromes. STATEMENT Write a program which reads a string and prints all palindromes, which can be obtained by removing of some characters of the string. The resulting palindromes do not need to be English words! Restrictions:
If anyone can find the problem and fix it, I appreciate it . CODE def check_palin(word): if word==word[::-1]: return True else: return False def all_palindromes(string): result=list() st1="" for i in range(0,len(string)): st1 += string[i] result.append(string[i]) for j in range(i+1,len(string)): st1+=string[j] if check_palin(st1)==True: result.append(st1) st1="" return list(set(result)) w = input("Write any string to find all palindromes: ") all_palindromes(w) RE: Help with Python - Palindromes - ndc85430 - Apr-04-2021 You don't have a call to print anywhere.Also, the if and else in check_palin are redundant.
RE: Help with Python - Palindromes - SantiagoPB - Apr-04-2021 (Apr-04-2021, 02:27 PM)ndc85430 Wrote: You don't have a call to I need to call the function to can see the result if it works good or not :S I tried with all_palindromes(w)but still not bring the result on the screen and really I dont know why. This if and else are just to check if the 1st string that I write as input is or not a palindrome, I don't know if is it the best option to do that but I am really new on python. RE: Help with Python - Palindromes - ndc85430 - Apr-04-2021 Well, you aren't printing anything are you? Why would you expect anything else to happen? All you do is call the function and throw its return value away. RE: Help with Python - Palindromes - buran - Apr-04-2021 Please, keep the discussion here https://python-forum.io/Thread-Palindromes-Python-Help?pid=140162#pid140162 I close this thread now. STOP creating new threads! |