Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE NOTE: THE WORD CHANGE MUST PERSIST WITHIN set_word INSTANCE. Write a python class library that evaluates and manipulates an English sentence. Create a class

PLEASE NOTE: THE WORD CHANGE MUST PERSIST WITHIN set_word INSTANCE.

Write a python class library that evaluates and manipulates an English sentence.

Create a class called Sentence that is in a file called Sentence.py and contains class attributes

and methods as follows:

A constructor that takes a sentence string as input.

The default value for the constructor should be an empty string

Converts the sentence to a list attribute

o First remove all punctuation

The sentence must be a private attribute in the class

get_all_words Method to get all the words in a sentence

Takes no arguments

Return: all the words in the sentence as a list

get_word Method to get one desired word from the sentence

Arguments: Number of the desired word, starting at 1

Return: The single word or an empty string for a number outside the range

It is okay for the program to crash on a noninteger argument

set_word Changes the word at a given index in sentence to a new word

Arguments: index, new_word

Does not return anything

PLEASE NOTE: THE WORD CHANGE MUST PERSIST WITHIN set_word INSTANCE.

scramble - Scrambles the words in a sentence

Takes no arguments

Return: a scrambled list of all the words in a sentence

o This does not change the sentence attribute in your sentence instance

A repr method use the builtin method

Return: The sentence list as a single string, with a period at the end

In Sentence.py, include a unit test

Place inside an if __name__ block

Instantiate the class with a sentence of your choice

Validate that the public methods in that instance work correctly

o Use assert to check for errors

At the end of your unit test, print a message that the sentence worked correctly and include

the final version of your sentence.

o For example Sentence unit test successful: my sentence

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

What are the challenges to our understanding of leadership?

Answered: 1 week ago