06 Prove Assignment: Troubleshooting Functions
Purpose
Prove that you can write a Python program and write and run test functions to help you find and fix mistakes.
Problem Statement
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
Assignment
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 determiner
-
a noun
-
a verb
-
a prepositional phrase
For example:
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:
-
main
-
get_determiner
-
get_noun
-
get_verb
-
get_preposition
-
get_prepositional_phrase
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 get_preposition
, get_determiner
, and get_noun
functions.
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:
-
test_get_determiner
-
test_get_noun
-
test_get_verb
-
test_get_preposition
-
test_get_prepositional_phrase
Helpful Documentation
-
The prepare content for this lesson explains how to troubleshoot functions and entire programs that are not working correctly.
-
The string
split
method 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.
Steps
Do the following:
-
Use the
get_determiner
function from the previous lesson’s prove milestone as an example to help you write theget_preposition
function. Theget_preposition
function 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. """
-
Write the
get_prepositional_phrase
function 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
main
function 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 -
In the
test_sentences.py
file that you wrote during the previous lesson’s prove milestone, write two functions namedtest_get_preposition
andtest_get_prepositional_phrase
that test theget_preposition
andget_prepositional_phrase
functions.Perhaps you are wondering what code you should write in the
test_get_prepositional_phrase
function. To answer that question, ask yourself, “What do we know about theget_prepositional_phrase
function?” From its description, we know theget_prepositional_phrase
function returns a string made of three words: a preposition, a determiner, and a noun. So you could write code in thetest_get_prepositional_phrase
function that calls theget_prepositional_phrase
function and then calls the Python stringsplit
method 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 anassert
statement that verifies that each word is the correct English part of speech.
Testing Procedure
Verify that your test program works correctly by following each step in this procedure:
-
Run your
test_sentences.py
program 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 =====================
-
Run your
sentences.py
program 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.
-
Within your
main
function add another call toget_prepositional_phrase
so 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_adjective
and call it in yourmain
function to add an adjective to the sentences produced by your program. Does it make sense to callget_adjective
in yourget_prepositional_phrase
function? -
In
test_sentences.py
write a function namedtest_get_adjective
that tests theget_adjective
function. -
Write a function named
get_adverb
and call it in yourmain
function to add an adverb to the sentences produced by your program. -
In
test_sentences.py
write a function namedtest_get_adverb
that tests theget_adverb
function.
Ponder
How hard would it be to modify your program to pass the Turing test?
Submission
To submit your program, return to I‑Learn and do these two things:
-
Upload your
sentences.py
andtest_sentences.py
files 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
-
Slightly deficient
-
Meets requirements
-
Exceeds requirements
-
Submission
Up Next
- :
Other Links:
- Return to: Week Overview | Course Home