167k views
3 votes
Import re

def compare_strings (string1, string2):
#Convert both strings to lowercase
#and remove leading and trailing blanks
string1 = string1.lower().strip()
string2 = string2.lower().strip()
#Ignore punctuation
punctuation = r"[.?!,;:-'"
string1 = re.sub (punctuation, r"", string1)
string2 = re.sub(punctuation, r"", string2)
#DEBUG CODE GOES HERE
print(_)
return string1 == string2
print(compare_strings ("Have a Great Day!", "Have a great day?")) # True
print(compare_strings ("It's raining again.", "its raining, again")) # True
Run
print(compare_strings ("Learn to count: 1, 2, 3.", "Learn to count: one, two, three."); # Fa
Reset
print(compare_strings ("They found some body.", "They found somebody.")) # False

can someone please help. don't answer, just help me please, someone tell me where I can start and how without letting me know the answer. I know its probably cheating, but a girl just needs some help. my first computer classes are I've done good so far, but this is just too hard​

User Blind
by
5.0k points

1 Answer

4 votes

I would recommend using for loops, isalpha() and isspace() to create two strings and compare those strings to each other.

User Hassana
by
5.3k points