Use quotes in output

My code works like it is supposed to.
I want the string to be in quotes, for example

  • "Kayak" is a palindrome
  • "Dog" is not a palindrome

But when I include quotes in the code then it just says
a is a palindrome

    a = input("Enter a word or sentence: ")
    b = a.lower()
    first = 0
    last = len(b) - 1
    pal = True
    while first < last:
        if b[first] == ' ':
            first += 1
        if b[last] == ' ':
            last -= 1
        if b[first] == b[last]:
            first += 1
            last -= 1
            pal = False
    if pal:
        print(a, "is a palindrome")
        print(a, "is not a palindrome")

>Solution :

If you put anything in quotes, python assumes it is a string. That means


prints a. If you want "a" to be printed you need to tell python to print the quotes and you text. Such as


In your case you can write:

print("\"" + a + "\"", "is a palindrome")  

For more information you can look into

Leave a Reply