University Wisconsin Milwaukee Returns the Number Python Problem Exercise
Question Description
I’m working on a Computer Science multi-part question and need an explanation to help me understand better.
Problem 2. Introduction
Here we will be counting e’s in text files, capitalized and uncapitalized, and accented and unaccented.
Your code in 2(b) must include a function called
count_letter_e(filename, ignore_accents, ignore_case)
That is, count_letter_e
:
- takes a filename, such as
"pg1342.txt"
, as input, and - returns the number of e‘s as output.
- includes two optional arguments,
ignore_accents
andignore_case
.- When
ignore_accents = True
, your function should count accented characters such as é, ê, and è as the same as e. - When
ignore_case=True
, your function should treat uppercase and lowercase e as the same letter. - The function
count_letter_e()
should return a single number, the total number of all characters that are being treated as equivalent to e. - Create other functions as necessary to organize your work.
- Include comments which explain the purpose and arguments of each function you create.
- The files are encoded as utf-8. When reading the files, you may have to specify the encoding.
- When
Problem 2(a). Design a Test Suite
Design a test suite (which will be in this case a set of input text) of at least four sentences that will allow you to quickly verify that all four optional argument possibilities are implemented correctly. Make sure that your test suite contains at least one of each of the 8 possible e’s (e, é, ê, è, E, É, Ê, È).
Save your test suite as a set of text files (1 sentence per text file) for use in your count_letter_e()
function, and also include each test sentence in a different markdown cell below. For each sentence, count each type of e by hand and report (in the markdown cell) what the output should be for the four possible combinations of true and false for ignore_case
and ignore_accents
.
*Note that you can complete this portion before you have written a single line of code for your function count_letter_e()
.
1
Test sentence 1:
2
* Sentence:
3
* Count with `ignore_case=True, ignore_accents=True`:
4
* Count with `ignore_case=True, ignore_accents=False`:
5
* Count with `ignore_case=False, ignore_accents=True`:
6
* Count with `ignore_case=False, ignore_accents=False`:
1
Test sentence 2:
2
3
Sentence:
4
Count with ignore_case=True, ignore_accents=True:
5
Count with ignore_case=True, ignore_accents=False:
6
Count with ignore_case=False, ignore_accents=True:
7
Count with ignore_case=False, ignore_accents=False:
Test sentence 3:
Test sentence 4:
Describe how you can use your four test sentences to detect problems in your implementation of count_letter_e()
. Why do you need four sentences, and not just one, or as many as 16?
Problem 2(b). Create and Test Your Code
Create the functions described in Problem 2 Introduction, and apply them to your test suite from 2(a). Do not use Python packages or code directly copied from online resources. Write your own functions from first principles.
Print the results of applying the four combinations of optional arguments of your count_letter_e()
function to your test suite. Verify that the output is correct. (If it isn’t, modify your code until your function works correctly on your test suite.)
In [ ]:
1
Problem 2(c). Apply Your Code
Apply your code from 2(b) to the two provided .txt
files for Pride and Prejudice and L’Enlèvement de la redoute. For each file, print the output of all four combinations of the boolean arguments to count_letter_e
.
In [ ]:
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."