Skip to content

Commit b696c33

Browse files
committed
recursive string checker
1 parent d145c84 commit b696c33

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

recursiveStrings.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
""" author: Ataba29
2+
code has a matrix each list inside of the matrix has two strings
3+
the code determines if the two strings are similar or different
4+
from each other recursively
5+
"""
6+
7+
8+
def CheckTwoStrings(str1, str2):
9+
# function takes two strings and check if they are similar
10+
# returns True if they are identical and False if they are different
11+
12+
if(len(str1) != len(str2)):
13+
return False
14+
if(len(str1) == 1 and len(str2) == 1):
15+
return str1[0] == str2[0]
16+
17+
return (str1[0] == str2[0]) and CheckTwoStrings(str1[1:], str2[1:])
18+
19+
20+
def main():
21+
matrix = [["hello", "wow"], ["ABSD", "ABCD"],
22+
["List", "List"], ["abcspq", "zbcspq"],
23+
["1263", "1236"], ["lamar", "lamars"],
24+
["amczs", "amczs"], ["yeet", "sheesh"], ]
25+
26+
for i in matrix:
27+
if CheckTwoStrings(i[0], i[1]):
28+
print(f"{i[0]},{i[1]} are similar")
29+
else:
30+
print(f"{i[0]},{i[1]} are different")
31+
32+
33+
main()

0 commit comments

Comments
 (0)