Exercise 69
Write a Python program as a function which takes a string s as parameter and which returns True if the string is duplicated and False if not. Example if s = "HelloHello", the function must returns True.
Solution
def duplicatedString(s):
n = len(s)
if n%2 ==0:
m = int(n/2)
if s[0:m] == s[m:]:
return True
else:
return False
else:
return False
# Examples
s1 = "HelloHello"
s2 = "Python"
print(duplicatedString(s1)) # display True
print(duplicatedString(s2)) # display False
Younes Derfoufi
my-courses.net
my-courses.net