Question: Python Need Help in English Thank you all files are in the google drive:https://drive.google.com/open?id=1cZGJ3nz7c4IYd2mxGiW4bk3VIlveHUVP The function should be named consonantReverse. This function will take a
Python
Need Help in English
Thank you
all files are in the google drive:https://drive.google.com/open?id=1cZGJ3nz7c4IYd2mxGiW4bk3VIlveHUVP
The function should be named consonantReverse. This function will take a string and return a new string (this is because in Python, strings are immutable) that has all consonants in the reverse order of the input string but leaving the vowels in their original place. Here are a few examples:
consonantReverse ('Data') 'taDa'
consonantReverse ('Algorithms') 'Asmohitrgl'
consonantReverse ('Structures') 'srtucruteS'
consonantReverse ('DataStructures') 'saratcrutSuteD'
The algorithm is not complicated. Let string be the string to which you would like to perform a consonantReverse. If s has a length less than or equals to 2, we are done; if string [0] is a vowel, we keep string [0] and recursively consonantReverse string [1:]; if string [-1] is a vowel, we keep string [-1] and recursively consonantReverse string [:-2]; otherwise, it must be the case that both string [0] and string [-1] are consonants, then we should keep both and recursively consonatnReverse string [1:-2].
Download the three files csc220a2Tester.py, csc220a2TestData.py, and csc220a2.py from Canvas and save them in the same folder. The first two files are the tester program and the testing data file, respectively. Do not modify these two files. The last file is the file you will work on. Note that you cannot rename this file and you cannot change the name of the function (otherwise the tester will not be able to pick up your implementation). However, you can change the name of the parameter if you like.
The file csc220a2.py contains a dummy implementation of the function that returns a hard-coded incorrect value:
def consonantReverse (inputString, start = 0, end = None): return ''
Note that in order to facilitate the recursion, we have added two parameters with default values. These two parameters will not be used by the tester, but it is needed by your function to call itself recursively.
The tester program will use the testing data to test your implementation. It will run a total of 100 test cases. If you have not made any change to the function, it should produce the following output:
Passed: [] - total 0. Failed: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] - total 100.
0 of 100 test cases passed. Score = 0.00 of 15.00
Notes:
1. You can assume that the input string contains only English letters (A-Z and a-z), no any other characters will appear in the input string.
2. Your function should not change the capitalization of characters in the string (see examples above).
3. Your program will be tested with similar but different data. The testing results will earn you up to 15 points this is your execution score.
4. There cannot be any import statement in your program otherwise, 20% of your execution score will be deducted.
5. There can be only one single function (the consonantReverse function) defined in the csc220a2.py file. No other helper method(s) is/are allowed. Otherwise, 20% of your execution score will be deducted.
6. You must have meaningful documentation (in form of comments) to explain what is going on in your implementation. Otherwise, 20% of your execution score will be deducted.
7. Your function cannot print anything to the screen otherwise, 20% of your execution score will be deducted.
8. Your function must be a recursive function otherwise, 90% of your total assignment score will be deducted.
9. Your implementation should be compatible to Python 3.x.
10. The tester contains a function runTestCase, this function takes a testcase number and run that single testcase. It will produce a more verbose output to help you debug your program.
>>> runTestCase (50) TC 50 failed - expecting 'PXiCxJRIMCAMKmpnnanHxiHSIyAdzPFZWEWeNmZlxwCewMICxxgYFYsakCvEBSQlSMoMsGozQ wJGuJRGoGxcuoKcGyJHUHtWlqoZDiHVCdSdRMOdiayDCXjlxNkZlBaIGsEHqvJbHFRJwqbpPzj UeROCVDRcHqbEyCuPEMiGiicVItqpPWsxZkGFRWeDFZUDiDuCiVIvGLkfaJsqmvcFgvYFwfQSA EbhySmOaPZZIUxCTNpUymvAsyynBJgUFioxMwlrypCTCpigcnqTjPLWbzyEQfJOmCWNUbslvBj vcaVxIWebNRqkhTaiFhCwDZakHPNNLzsAmoWGhumPSaCffMFxQcFCzNWGujcpwvCPQYbKnHgrV ekDEmcNKOTpAZBVTJAaSXSdhBvERJIYNNGXbLXlRZhXFXFFdHpVliazQwUMfGOoDmEfETzfpjX KsNHJJnkfOqkXPkmVsIdYPRFWeEXWUpvfjOOmfYzqIhTHUTAwUuspVYwxkVEbKPlWZsWYQUEvK jMntALSeEZjHcNqiUYYCiCSkLKjlHLwBhvaICHpzBEVgKshubedBLUbLeYviGzzAzAfxOSUszj XKghMvPaWHFROvEdagwUFgqNtVMzAWqXbKRivhlXuNPDSfWJwbOMJKSxzWiuytftHznZTWyRAj pPNqyHlHEKOShArIHpKBDxwsScCuzhyoWojHZaOxxStHNbVJuEcJNXFByHirzyNIyIFAhwidBj iZFfFyMgYIWpPMoFkGMYfvinOccIoaoWokRKgFhCmKRgvtiFUZIQbLxFfezgdaCMaMqbYxjEJY ZBfJEqxdWLFJHpQqMiWOVfKXZjLhDGNrzIAffzQqUiCBvrbYaDSsCOCFoPjEUzZdjBHGEyyJYZ MCSPIshXJduBIvgFmvBzleQkIOMDQvEsyVftCRKyPsEAKMGWSwpJGkZAaxtBVxuuclGxOETYlB KPbiWhNlxeoetXmSgDGno', got '' instead
Please note that this function is not executed by default when you load the tester. So, you may need to somehow activate Python in interactive mode in order to use this function. If you are using Python IDLE, you are automatically put in the interactive mode after loading (and executing) the module. However, this is not the default if you are invoking and running Python from the command line. To allow you to use the function if you load the tester from the command line, you must use the interactive flag when invoking Python:
> python -i csc220a2Tester.py
After you are done, you can use either the exit () function or the CTRL-C key combination to abort the Python session. 11. Your function should have performance linear to the length of the input string
This can be a problem since Python strings are immutable. If you return a new string during each recursive step, your function will have (2) performance. This is because the returned string during each recursive step will need to be copied, and each copy operation has an () performance.
To solve this problem, we will need to first convert the string into a list of characters, then the reverse operation can be performed on the list; and convert the list back into a string just before returning from the original call. Therefore, you may have to do something similar to the following:
def consonantReverse (data, start = 0, end = None):
if type (data) == str:
charList = list (data)
consonantReverse (charList)
return ''.join (charList)
Please note that if you adopt this approach, you must also use recursion in you code when handling list (of characters) input (or anything similar). That is, the recursive call used in the above given code does not count.
What i have done so far
all files are in the google drive:https://drive.google.com/open?id=1cZGJ3nz7c4IYd2mxGiW4bk3VIlveHUVP
# Part 1:
def consonantReverse (data, start = 0, end = None): return ''
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
