Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

Students also viewed these Databases questions