MAD LIBS-how to code it in python

Assignment Help Basic Computer Science
Reference no: EM133218128

This set of problems and how to code it in python.

MAD LIBS

A Mad Lib is a story template that has many missing words, each indicated by a label giving the category (part of speech) of the missing word. For example, a story template will contain the word NOUN in many places instead of specific nouns, the word ADJECTIVE in many places instead of specific adjectives, etc. Before reading the story, the reader asks listeners to provide the missing words without indicating where and how the words will be used in the story. If, for example the story template is: Once upon a NOUN, three PLURAL NOUN VERB PAST in the NOUN. The reader would first ask "Give me a noun" to which the listener might reply "piano". The reader would then ask "Give me a plural noun" and the listener might say "hamburgers". The reader would next ask "Give me a past tense verb" and the listener might say "frolicked". Finally, the reader would ask "Give me a noun" and the listener might say "dumpster". The reader replaces the missing words with those provided by the listener and reads the result: Once upon a piano, three hamburgers frolicked in the dumpster. At this point everyone in the room giggles until their eyes water. Create a program that reads a Mad Lib story template from a file (template files will be provided to you). The Mad Lib template files may contain any of the following part of speech labels:

• NOUN

• PLURAL NOUN

• VERB

• VERB PAST

• ADJECTIVE

The program asks the user to supply each of the needed words and writes out the completed version of the story to a new file (Note: the label VERB on its own indicates present tense). You may assume that the two part of speech labels with two words (PLURAL NOUN and VERB PAST) will never be split over two lines in the file. The

program will also print a simple numerical analysis of the contents of the file (explained below).

1.1. DETAILS

Make a new file called madlib.py. In the file:

1. Make a function called print_report that takes a single string parameter for the name of a file.

The function will:

i. Read the given file and print a report giving the following information:

a) the total number of vowels in the file (for this assignment y is not a vowel)

b) the total number of consonants in the file

c) the total number of white spaces in the file (spaces, tabs, newlines)

d) the total number of punctuation characters in the file (for this assignment assume that punctuation is anything that is neither a letter from the alphabet nor a white space)

e) the total number of characters in the file

f) the percent of the file composed of vowels, consonants, white spaces, and punctuation characters.

g) begin and end with a blank line.

ii. The function should print the report in a pretty table similar to the one shown in the following example.

-------tortoise.txt------

Vowels: 232

Consonants: 368

Whitespace: 150

Punctuation: 22

-------------------------

Total: 772

Percent vowels: 30.1

Percent consonants: 47.7

Percent spaces: 19.4

Percent punctuation: 2.8

In order to make the table that looks like this one, you must have the file name centered in a line of dashes, 25 total characters, the alphabetical text should be left justified in a field of length 20 and the numbers (as strings) should be right justified in a field of length 5.

• For the percents, you'll need to use the built in round function. Here's an example:

round(3.14159265, 4)

--> 3.1416

- Experiment with it in a shell until you know how to use it.

- Hint: it might be a good idea to make your own text file to test this code on. For example, you might first try it with a file that has exactly 5 vowels in it and nothing else...

-Test your function and verify it works correctly before moving on.

- REMEMBER THAT SPACES AREN'T THE ONLY FORM OF WHITESPACE

2. Make a function called replace_parts_of_speech that takes two parameters. The first is a string representing a line from a file. It may contain part of speech labels that need to be replaced by words (e.g."The ADJECTIVE NOUN in the NOUN VERB PAST."). The second is a string indicating which part of speech label to replace,e.g. "NOUN".

i. For each occurrence of the given part of speech in the given string ask the user for a word of the appropriate type.

ii. Replace the part of speech label with the word provided by the user

iii. After replacing all parts of speech of the indicated type, return the new version of the given string

- For example, calling the function like this: replace_parts_of_ speech("the NOUN VERB PAST the NOUN", "NOUN") would cause the function to ask the user to enter a noun twice. Assuming the user entered "dog" for the first noun and "duck" for the second, the function would return: "the dog VERB PAST the duck"

Note: When asking the user for words, your prompts should like these examples:

Enter noun:

Enter plural noun:

Enter verb:

Enter verb past:

Enter adjective:

*Test your function and verify it works correctly before moving on.*

3. Make a function called complete_mad_lib that takes a string parameter for the name of a Mad Lib template file to read. The function will:

i. Read the indicated template file line by line and

• Replace all part of speech labels with words entered by the user

- you'll need to figure out how to use the function you wrote to accomplish this

- Do it in this order:

PLURAL NOUN, VERB PAST, VERB, NOUN, ADJECTIVE

ii. Write the completed story out to a new file:

• the new file should have the same name as the original file, prepended with the string "MAD_"

(e.g. if the original file was named "tortoise.txt" the new file should be "MAD_tortoise.txt")

*Test your function and verify it works correctly before moving on.*

4. In main do the following:

i. Ask the user to enter the name of a Mad-Lib template file (assume the file is inthe same directory as this program)

ii. Call your function to print the character report on that file

iii. Call your function to have the user complete the Mad Lib story

5. Verify that your documentation makes sense and that you've added documentation to each of your functions.

Reference no: EM133218128

Questions Cloud

Relational schemes for the tables : Map the following ER model to a relational DBMS schema. Only show the relational schemes for the tables
Review existing international plastics network diagrams : Review the existing International Plastics network diagrams and update each of the four location diagrams with recommendations for IT infrastructure improvement
Code functions and button click even procedure : The Translate button should then display the translated word in the label. Code the functions and the button's Click even procedure.
Specializes in business travel : Jack forester and Lisa Turner are systems analysts in the IT Department of TravelBiz, a nationwide travel agency that specializes in business travel.
MAD LIBS-how to code it in python : A Mad Lib is a story template that has many missing words, each indicated by a label giving the category
Saving account-multiple transactions : You will be focusing on allowing multiple transactions to be completed by the user. You will include defensive programming
Academic journals on information technology sourcing : Find 2 peer-reviewed articles from academic journals on information technology sourcing.
Description of the king iii framework : Analysis on how King III framework position the company at a competitive advantage.
Should be made to the organisation development plan : Based on the survey responses, indicate any changes that should be made to the organisation development plan.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Delivering essential services internationally

The private sector are struggling to provide a secure, efficient, timely, and separate means of delivering essential services internationally.

  Rural residence suspected of containing

One night, a sheriff's department helicopter lands a SWAT team in the yard of a rural residence suspected of containing a methamphetamine lab.

  Standardized test scores-sat scores

Discuss the incentives for school principals (who are the agents, in this case) under this scheme and how you might improve them.

  Compare the performance of two binary search trees

Generate 10 random values between 0 and 8000. Add these values to each tree in the same order. After each of these additions, update each tree's comparisonSum variable by the number of comparisons performed for the insertion.

  Explain the dynamic nature of conflict

Explain the dynamic nature of conflict. Discuss the conflict process and the five dimensions involved.

  Counting massless gauge fields

Consider a string compactification where k coordinates are made into circles of critical radius. Describe the candidate ground states of this theory, and give the expression for the Hamiltonian.

  Dealing with systems analysis

You will type on the a topic dealing with Systems Analysis.

  How you feel about the need for internet privacy

Explain how you feel about the need for Internet privacy. If you value your own privacy, explain why you do.

  Influence to change or upgrade security software

What is your influence to change or upgrade your security software? Have you made a change and regretted it before?

  Seven domains of a typical it infrastructure

Why would gap analysis be used and how would it be used in one of the seven domains of a typical IT infrastructure?

  Calculate cycle time based on with/without pipeline

For a single cycle computer system, how to calculate the cycle time based on with/without pipeline?

  Social and mobile web technologies

Describe how Interaction Design in social and mobile Web technologies influences a user to seek information or purchase products online?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd