Python Forum
Palindrome checker case sensive
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Palindrome checker case sensive
#1
Hello,

Got a task to make a palindrome checker for user input now my script so far works UNLESS the first there is a cApiTal letter in it. E.g. Abba will return a negative palindrome while abba will return positive. I don't know how i can tell python to 'ignore' letter cases

Current script:
def reverse(s):
    return s[::-1]


def isPalindrome(s):
    rev = reverse(s)

    if (s == rev):
        return True
    return False

s = str(input("Enter a string"))
ans = isPalindrome(s)

if ans == 1:
    print("Yes")
    s = str(input("Enter a string"))
else:
    print("No")
    s = str(input("Enter a string"))
Reply
#2
Ignoring case in Python is generally done by lowercasing everything, such as s.lower().
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Also, input() returns a string, so str(input("Enter a string")) is redundant.
s = input("Enter a string: ").lower()
And, isPalindrome(s) returns boolean, so you could combine lines 13 and 15 as
if isPalindrome(s) :
Reply
#4
(Nov-05-2019, 03:16 PM)edwdas Wrote:
ans = isPalindrome(s)
 
if ans == 1:

Are you a C programmer?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Program to check whether a number is palindrome or not PythonBoy 18 2,479 Sep-12-2023, 09:27 AM
Last Post: PythonBoy
  Password Checker Assignment mcostello 1 5,016 Nov-14-2020, 07:54 AM
Last Post: DPaul
  "Travis" guest list name checker (Ziyad Yehia Udemy course) Drone4four 8 3,906 Aug-24-2019, 03:46 PM
Last Post: jefsummers
  Syntax checker BZA 4 3,142 May-16-2019, 06:40 PM
Last Post: BZA
  Palindrome program - I can't figure it out. Gabar112 3 3,504 Feb-20-2018, 07:03 PM
Last Post: Larz60+
  Palindrome.strip pirts.emordnilaP RodNintendeaux 4 3,813 Oct-08-2017, 02:30 AM
Last Post: RodNintendeaux
  Spell Checker Liquid_Ocelot 1 3,154 May-07-2017, 11:28 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020