Question: USING RECURSION ONLY...NO ITERATION Write a module called advancedmatch.py recursive function called match(pattern, word) that can be used to determine if a given pattern matches

USING RECURSION ONLY...NO ITERATION

Write a module called advancedmatch.py recursive function called match(pattern, word) that can

be used to determine if a given pattern matches a given word.

In this case, a pattern consists of letters and ? and * wildcards.

A ? wildcard matches any letter at the corresponding position in the word.

A * wildcard matches zero or more letters at the corresponding position in the word.

Use aprogram called testadvanced.py that can be used to check your function.

Sample I/O:

Enter a pattern (or 'q' to quit):

l*ad

Enter a word:

launchpad

It's a match.

Enter a pattern (or 'q' to quit):

*ad

Enter a word:

lead It's a match.

Enter a pattern (or 'q' to quit):

**ad

Enter a word:

lard

They don't match.

Enter a pattern (or 'q' to quit):

q

HINTS:

? We now have an extra base case: if word is and pattern is * then return True.

? Generally, when the first character of the pattern is a * wildcard, try to (i) match the rest of the pattern to the word, or (ii) match the pattern to the rest of the word.

Advancedmath:

import advancedmatch

def main(): pattern = input("Enter a pattern (or 'q' to quit): ") while (pattern!='q'): word = input("Enter a word: ") if (advancedmatch.match(pattern, word)): print("It's a match.") else: print("They don't match.") pattern = input("Enter a pattern (or 'q' to quit): ") if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!