Write a recursive function in Python, compare,to compare two strings, s1 and s2. Your function should output 1 ifs1 is equal to w2 and 0 otherwise.
compare(‘abc’,’adc’) will output 0
compare(‘abc’,’abc’) will output 1
Solution
def compare(s1, s2): if s1 == ”: return s2 == ” elif s2 == ”: return s1 == ” else: return s1[0] == s2[0] and compare(s1[1:], s2[1:])print(compare(‘abc’, ‘adc’))print(compare(‘abc’, ‘abc’))