06 Prove Assignment: Troubleshooting Functions
Prove that you can write a Python program and write and run test functions to help you find and fix mistakes.
The Turing test, named after Alan Turing, is a test of a computer’s ability to make conversation that is indistinguishable from human conversation. A computer that could pass the Turing test would need to understand sentences typed by a human and respond with sentences that make sense.
In English, a preposition is a word used to express spatial or temporal relations, such as “in”, “over”, and “before”. A prepositional phrase is group of words that begins with a preposition and includes a noun. For example:
above the water
in the kitchen
after the meeting
Write the second half of the Python program that you began in the previous lesson’s prove milestone, a program that generates simple English sentences. During this prove assignment, you will write and test functions that generate sentences with four parts:
a prepositional phrase
One girl talked for the car.
A bird drinks off one child.
The child will run on the car.
Some dogs drank above many rabbits.
Some children laugh at many dogs.
Some rabbits will talk about some cats.
To complete this prove assignment, your program must include at least these six functions:
You may add other functions if you find them helpful. The
get_preposition function must randomly choose a preposition from a list and return the randomly chosen preposition. The
get_prepositional_phrase function must make a prepositional phrase by calling the
In addition, to complete this prove assignment, you must write and submit a file named
test_sentences.py that contains five functions named as follows:
The prepare content for this lesson explains how to troubleshoot functions and entire programs that are not working correctly.
splitmethod separates a string of text into words and returns a list of strings.
Help from a Tutor
As a BYU-Idaho campus or online student you can get help from a tutor to complete your CSE111 assignments. Each tutor is a current BYU-Idaho student employed by BYU-Idaho. Meeting with a tutor is free. It will not cost you any money to meet with a tutor. To get help from a tutor, you simply make an appointment and then meet with the tutor. Campus students meet with tutors in the tutoring center. Online students meet with tutors in Zoom. To make an appointment, follow the instructions in the course tutoring guide.
Do the following:
get_determinerfunction from the previous lesson’s prove milestone as an example to help you write the
get_prepositionfunction must have the following header and fulfill the requirements of the following documentation string.
def get_preposition(): """Return a randomly chosen preposition from this list of prepositions: "about", "above", "across", "after", "along", "around", "at", "before", "behind", "below", "beyond", "by", "despite", "except", "for", "from", "in", "into", "near", "of", "off", "on", "onto", "out", "over", "past", "to", "under", "with", "without" Return: a randomly chosen preposition. """
get_prepositional_phrasefunction to have the following header and fulfill the requirements of the following documentation string.
def get_prepositional_phrase(quantity): """Build and return a prepositional phrase composed of three words: a preposition, a determiner, and a noun by calling the get_preposition, get_determiner, and get_noun functions. Parameter quantity: an integer that determines if the determiner and noun in the prepositional phrase returned from this function should be single or pluaral. Return: a prepositional phrase. """
Add code to the
mainfunction and write any other functions that you think are necessary for your program to generate and print six sentences, each with a determiner, a noun, a verb, and a prepositional phrase. The six sentences must have the following characteristics:
Quantity Verb Tense a. single past b. single present c. single future d. plural past e. plural present f. plural future
test_sentences.pyfile that you wrote during the previous lesson’s prove milestone, write two functions named
test_get_prepositional_phrasethat test the
Perhaps you are wondering what code you should write in the
test_get_prepositional_phrasefunction. To answer that question, ask yourself, “What do we know about the
get_prepositional_phrasefunction?” From its description, we know the
get_prepositional_phrasefunction returns a string made of three words: a preposition, a determiner, and a noun. So you could write code in the
test_get_prepositional_phrasefunction that calls the
get_prepositional_phrasefunction and then calls the Python string
splitmethod to separate the returned phrase into a list of words and verifies that the length of the list is three. In addition for each word in the list, you could write an
assertstatement that verifies that each word is the correct English part of speech.
Verify that your test program works correctly by following each step in this procedure:
test_sentences.pyprogram and verify that all five of the test functions pass. If one or more of the tests don’t pass, find and fix the mistakes in your program functions or test functions until the tests pass as shown in this output:
> python test_sentences.py=================== test session starts ====================platform win32--Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggyrootdir: C:\Users\cse111\lesson06collected 5 itemstest_sentences.py::test_get_determiner PASSED [ 20%]test_sentences.py::test_get_noun PASSED [ 40%]test_sentences.py::test_get_verb PASSED [ 60%]test_sentences.py::test_get_preposition PASSE [ 80%]test_sentences.py::test_get_prepositional_phrase PASSED [100%]==================== 5 passed in 0.10s =====================
sentences.pyprogram and ensure that your program’s output is similar to the sample run output shown here. Because your program randomly chooses the determiners, nouns, verbs, and prepositions, your program will generate different sentences than the ones shown here.
> python sentences.pyOne girl talked for the car.Some dogs drank above many rabbits.One bird drinks off one child.Some children laugh at many dogs.The child will run on the car.Some rabbits will talk about some cats.
Exceeding the Requirements
If your program fulfills the requirements for this assignment as described in the previous prove milestone and the Assignment section above, your program will earn 93% of the possible points. In order to earn the remaining 7% of points, you will need to add one or more features to your program so that it exceeds the requirements. Here are a few suggestions for additional features that you could add to your program if you wish.
mainfunction add another call to
get_prepositional_phraseso that each sentence includes two prepositional phrases like this:
One girl across one cat talked for the car.
A bird near the rabbit drinks off one child.
The child under the cat will run on the car.
Some dogs without a cat drank above many rabbits.
Some children from a bird laugh at many dogs.
Some rabbits behind one man will talk about some cats.
Write a function named
get_adjectiveand call it in your
mainfunction to add an adjective to the sentences produced by your program. Does it make sense to call
test_sentences.pywrite a function named
test_get_adjectivethat tests the
Write a function named
get_adverband call it in your
mainfunction to add an adverb to the sentences produced by your program.
test_sentences.pywrite a function named
test_get_adverbthat tests the
How hard would it be to modify your program to pass the Turing test?
To submit your program, return to I‑Learn and do these two things:
test_sentences.pyfiles for feedback.
Add a submission comment that specifies the grading category that best describes your program along with a one or two sentence justification for your choice. The grading criteria are:
Some attempt made
Developing but significantly deficient
- Return to: Week Overview | Course Home