2.8. Repeated Strings ¶
In this question it is asked to determine whether the first half of a string is exactly the same of its second half. If the string is not halvable (i.e. has odd number of elements) then and error message has to be printed.
For example, “abab” is such a string. When it is divided into two
equal parts, the parts are “ab” and “ab” and these are the same. On
the other hand, “abba” is not such a string, because the two halves
are “ab” and “ba” and they are not the same. If the input string is
such a ‘repeated string’, you should print “Yes”, otherwise, you
should print “No”. If the length of the string is odd then print
“Error”.
Sample I/O:
Input:
abaaba
Output:
Yes
Input:
abbbba
Output:
No
Input:
a
Output:
Error
Input:
aba
Output:
Error
string = input()
result = "Yes"
if len(string) % 2 == 0:
for index in range(0, int(len(string)/2)):
if string[index] != string[int(len(string)/2) + index]:
result = "No"
break
else:
result = "Error"
print(result)