This code checks for palindrome
if yes, NULL is printed
if no, characters to be added to make it palindrome is printed
if input = malay, output = alam
but, if input = abcdc, output = dba why?
"But if I input 'ma', I get 'm' as output"
Yes, because 'ma' + 'm' -> 'mam' is palindrome.
To get 'am' simply don't slice, print( rev_msg ) rather than print( rev_msg[ 1 : ] ).
But this way we have twin character at the center.
You can also take length of <msg> as consideration. If length of <msg> was odd, slice <rev_msg>, otherwise don't slice.
No, I don't mind at all.
I meant to say, you can ask, in case there's something you don't clearly understand from the code I posted. It's important to understand.
rev_msg[ 1 : ] returns a slice of <rev_msg> from second character (index 1) up to the last.
msg = "abcdc"
rev_msg = "cdcba" # reversed
rev_msg[ 1 : ] = "dcba" # slice from second character
Because we want to append a reversed string <rev_msg> at the end of <msg> to make <msg> palindrome. But to achieve that, we skip the first character from <rev_msg> cause it will become the center character.