CS 521 UCI Python Class Library Problem

User Generated

Qbbcbz

Programming

University of California Irvine

Question Description

Help me study for my Python class. I’m stuck and don’t understand.

Unformatted Attachment Preview

CS‐521 Homework Assignment 6 Assignment Directions The specific instructions for these programming exercise is adapted from a problem in the textbook. Make sure to follow the specific instructions in THIS document. The program is worth 100 points (100%). Style Requirements For all assignments, follow the guidelines in the PEP8 Standards and Best Practices that have been shared to date, along with course specific requirements. Remember the following elements to avoid minor deductions: New elements since last week’s assignment are in bold.           Name your program properly Name objects appropriately o variables and functions must use snake_case (lower case plus underscores) o CONSTANT variables in all upper case o Class objects must start with an Uppercase letter Include docstrings, this includes: o At the start of your program o Immediately after function definitions o Immediately after class object definitions o Immediately after method definitions Include an adequate # line comments (just a few in each program, don’t go crazy) o Line comments must be indented to match code lines Keep all code/comment lines under 80 characters Clearly explain the output you are printing (where not obvious) Trap errors from bad user input that might cause code to crash Keep scope for try blocks VERY small – generally one or two commands Use format() or format strings f’ ()’ to round output and add thousand separating commas (US standards) o 123456.126 should be 123,456.13  '{:,.2f}'.format(123456.126) NEVER use a “main()” function o Or any function that neither has input arguments nor return values 1 CS‐521 Homework Assignment 6 Chapter 11 Exercise 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.     get_all_words — Method to get all the words in a sentence    Arguments: index, new_word Does not return anything scramble – Scrambles the words in a 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 non‐integer argument The word change must persist within the instance set_word — Changes the word at a given index in sentence to a new word    Takes no arguments Return: all the words in the sentence as a list get_word — Method to get one desired word from the sentence      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 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 built‐in 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 No other program is required. Where to submit? Click Assignments in the Navigation Area and then click on the title of the assignment to enter the submission area and upload your Sentence.py program. This does not have to be in a zip file. 2
Purchase answer to see full attachment
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Explanation & Answer

View attached explanation and answer. Let me know if you have any quest...

kv_kkv (790)
Boston College

Related Tags