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):\n")
while (pattern!='q'):
word = input("Enter a word:\n")
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):\n")
if __name__ == '__main__':
main()
def match(first, second):
if len(first) == 0 and len(second) == 0:
return True
if len(first) > 1 and first[0] == '*' and len(second) == 0:
return False
if (len(first) > 1 and first[0] == '?') or (len(first) != 0
and len(second) !=0 and first[0] == second[0]):
return match(first[1:],second[1:]);
if len(first) !=0 and first[0] == '*':
return match(first[1:],second) or match(first,second[1:])
return False
def test(first, second):
if match(first, second):
print("It's a match.")
else:
print("They don't match.")
pattern = input("Enter a pattern (or 'q' to quit):\n")
while (pattern!='q'):
word = input("Enter a word:\n")
test(pattern, word)
pattern = input("Enter a pattern (or 'q' to quit):\n")
USING RECURSION ONLY...NO ITERATION Write a module called advancedmatch.py recursive function called ‘match(pattern, word)’ that can...
Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...
Summary You will write an application to build a tree structure called Trie for a dictionary of English words, and use the Trie to generate completion lists for string searches. Trie Structure A Trie is a general tree, in that each node can have any number of children. It is used to store a dictionary (list) of words that can be searched on, in a manner that allows for efficient generation of completion lists. The word list is originally stored...
I need only one C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...
Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...
This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...
Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following: Writing a while loop Writing a for loop Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...
The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...
For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...