Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prove that you can write a Python program and write and run testfunctions to help you find and fix mistakes. Problem Statement The Turing test,

Prove that you can write a Python program and write and run testfunctions to help you find and fix mistakes.

Problem Statement

The Turing test, named after Alan Turing, is a test of acomputer's ability to make conversation that is indistinguishablefrom human conversation. A computer that could pass the Turing testwould need to understand sentences typed by a human and respondwith sentences that make sense.

In English, a preposition is a word used to expressspatial or temporal relations, such as "in", "over", and "before".A prepositional phrase is group of words that begins witha 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 inthe previous lesson's prove milestone, a program thatgenerates simple English sentences. During this lesson, you willwrite and test functions that generate sentences with fourparts:

  1. a determiner

  2. a noun

  3. a verb

  4. a prepositional phrase

For example:

One girl talked for the car.
Some dogs drank above many adults.
One bird drinks off one child.
Some children laugh at many dogs.
The child will run on the car.
Some adults will talk about some cats.

After this lesson, your program must include at least these sixfunctions:

  • main

  • get_determiner

  • get_noun

  • get_verb

  • get_prepositional_phrase

  • get_preposition

You may add other functions if you want.The get_preposition function must randomly choose apreposition from a list and return the randomly chosen preposition.The get_prepositional_phrase function must make aprepositional phrase by callingthe get_preposition, get_determiner,and get_noun functions.

Helpful Documentation

The prepare content for this lesson explains how totroubleshoot functions and entire programs that are not workingcorrectly.

Steps

Do the following:

  1. Use the get_determiner function from the previouslesson as an example to help you writethe get_preposition function.The get_preposition function must have the followingheader and fulfill the requirements of the following documentationstring.
    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.    """
  2. Write the get_prepositional_phrase function to havethe following header and fulfill the requirements of the followingdocumentation 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 nouns are singular or plural.    Return: a prepositional phrase.    """
  3. Add code to the main function and write any otherfunctions that you think are necessary for your program to generateand print six more sentences with the following characteristics.Each of these six additional functions must include a prepositionalphrase.

    Grammatical NumberVerb Tense
    a.singularpast
    b.pluralpast
    c.singularpresent
    d.pluralpresent
    e.singularfuture
    f.pluralfuture
  4. In the test_sentences.py file write two functionsnamed test_get_preposition and test_get_prepositional_phrase thattestthe get_preposition and get_prepositional_phrase functions.

    Perhaps you are wondering what code you should write inthe test_get_prepositional_phrase function. To answerthat question, ask yourself, "What do we know aboutthe get_prepositional_phrase function?" From itsdescription, we knowthe get_prepositional_phrase function returns a phrasemade of three words: a preposition, a determiner, and a noun. Soyou could write code inthe test_get_prepositional_phrase function that callsthe get_prepositional_phrase function and then assertsthat the string returnedfrom get_prepositional_phrase contains three wordsseparated by spaces. In addition, you could write code that callsthe Python string split method to split the returnedphrase into its three words and checks each of the three words.

Testing Procedure

Verify that your test program works correctly by following eachstep in this procedure:

  1. Run your test_sentences.py program and verify thatall five of the test functions pass. If one or more of the testsdon't pass, find and fix the mistakes in your program functions ortest 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, pluggy-0.13rootdir: C:Userscse111lesson06collected 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 PASSED            [ 80%]test_sentences.py::test_get_prepositional_phrase PASSED   [100%]====================== 5 passed in 0.10s =======================
  2. Run your sentences.py program and ensure that your program'soutput is similar to the sample run output shown here. Because yourprogram will randomly choose the determiners, nouns, verbs, andprepositions, your program will generate different sentences thanthe ones shown here.
    > python sentences.pyOne girl talked for the car.Some dogs drank above many adults.One bird drinks off one child.Some children laugh at many dogs.The child will run on the car.Some adults will talk about some cats.

Step by Step Solution

3.40 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

1 getpreposition function Python def getpreposition Return a randomly chosen preposition from a list ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics

Authors: Austan Goolsbee, Steven Levitt, Chad Syverson

1st Edition

978-1464146978, 1464146977

More Books

Students also viewed these Programming questions

Question

6.8 Find a z o such that P(-z

Answered: 1 week ago