- define a string
- define string’s len
- print true if the string len is even and the right half identical to the left half, else – print false.
I need to do it only in 3 lines and it has to work for every string len without change the condition in (3).
We didn’t learn or loop yet. It supposed to be with slice.
please help.
i tried to do it:
some_string = "bb"
str_len = len (some_string),str(a)
if str_len%2==0 and some_string[0:a/2]==some_string[a/2:0]: print "True"
else: print "False"
but something went wrong
Your code is almost fine, just a little improvement needed. You don’t actually need to check for even length using
modulus(%)operator, as the second condition will automatically take care of it.So, Here’s how your code would look: –