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

    #!/usr/bin/python3 
    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
            continue
        if b[last] == ' ':
            last -= 1
            continue
        if b[first] == b[last]:
            first += 1
            last -= 1
        else:
            pal = False
            break
    
    if pal:
        print(a, "is a palindrome")
    else:
        print(a, "is not a palindrome")

>Solution :

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

print("a")

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

print("\"a\"")

In your case you can write:

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

For more information you can look into https://docs.python.org/3/tutorial/inputoutput.html

Leave a Reply