0

Why following code is raising error?

def palindrome(c) : return c == c[ :: -1] if yes : print(len(s)-1) else: print(len(s)) s=input("enter the string:") print(palindrome(s))

25th Feb 2020, 4:27 PM
Amey Godse
Amey Godse - avatar
3 ответов
+ 2
It is not raising any error... If you are talking about wrong output then it might be because you are comparing Capital letter with smaller ones... In your code Racecar == racecaR Will be false, while it is a palindrome to fix this return c.lower() == c[::-1].lower() And everything after return will not be executed so there is no point in adding something after it... You can see the edited code. https://code.sololearn.com/c9BQB12IhXya/?ref=app
25th Feb 2020, 4:41 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 2
Amey Godse If you want the code to print if else, then you have to put return at end. Nothing after the return is executed. I have fixed it in the code given...
25th Feb 2020, 4:45 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
0
I am asking why code is not printing if and else condition output ?
25th Feb 2020, 4:44 PM
Amey Godse
Amey Godse - avatar