Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COMP202 – Foundations of Programming Assignment
Important notice
Make sure that all file names and function names are spelled exactly as described in this document. Otherwise, a 50% penalty per question will be applied. You may make as many submissions as you like prior to the deadline, but we will only grade your final submission (all prior ones are automatically deleted).
Word search
In this assignment, we will create a simpler version of the word search algorithm. Let’s say we have a list of letters:
And the following list of words:
‘WIKIPEDIA’, ‘RANDOM’
Then the program will find both words in the list of letters (they could be found from left to right or from right to left). Once all the words are found in the list, the program will search for free letters in the list sequentially (letters that do not belong to any of the words).
These letters will constitute the mystery word. So in this example, we can find the words ’WIKIPEDIA’ (from left to right) and ’RANDOM’ (from right to left) in the list:
There are 4 remaining letters (shown in orange) and if we assemble them from left to right it will give us the following magic word : ‘COMP’. In the following function descriptions:
Question 1: is outside list(letter list,index)[5 points]
– a list of letters letter list (a list of characters)
– an index (integer)
– if letter list = [’A’,’B’,’C’,’D’] and index = 4, then the function will return True (the only valid indices are 0, 1, 2 and 3).
– if letter list = [’A’,’B’,’C’,’D’], then the function will return False if index = 2 or index = 0
– if letter list = [’A’,’B’,’C’,’D’] and index = -2, then the function returns True (even though in Python we can access indices of negative values, this function also considers negative indices as outside of the list)
Question 2: letter positions(letter list,character)[5 points]
– a list of letters letter list (a list of characters)
– a character to search for in the list
– Do not use the index() or find() or count() methods or any other method/function that we didn’t see in class,
– You HAVE to use a loop to traverse the list.
– if letter list= [’A’,’B’,’C’,’D’] and we are looking for character ’Z’, then the function will return an empty list []
– if letter list= [’A’,’B’,’C’,’D’,’C’,’M’] and we are looking for character ’C’,then the function will return the following list: [2,4]