Bentley University
Python Programming代写 Mad Libs is a word game where one player prompts others for a list of words to substitute for blanks in a story
CS 230
Introduction to Programming with Python
Homework 4: Mad Libs Python Programming代写
Mad Libs is a word game where one player prompts others for a list of words to substitute for blanks in a story, before reading the – often comical or nonsensical – story aloud. In this assignment you will write a program to play Mad Libs.
Start with the story, in a text file whose name the player enters at the start of the program.
Humpty Dumpty
Humpty Dumpty sat on a [noun]
Humpty Dumpty had a great [season_of_the_year]Python Programming代写
All the [government_official] ‘s [animal_(plural)]
and all the [government_official] ‘s [group_of_people]
Couldn’t [verb_meaning_create] Humpty Dumpty back together again.
The first line of the text file is the title of the story. Each additional line is a line in the story. Words to substitute are identified by the [square brackets] and the desired response type is shown in the square brackets, for example [noun]. If the word to substitute is a phrase, then individual words are joined with an underscore, as in [government_official] . (Don’t worry about the fact that the apostrophe-s combination is treated as a separate word.)
After entering the name of the Mad Lib text file (such as madlib.txt) , the program will ask if the player wants to see the Mad Lib with the answers from last time the program was run, or if the player wants to enter new answers.Python Programming代写
If the player wants to enter new answers, the program will read the Mad Lib text file and will ask the question “Enter a ” followed by each word or phrase in brackets. If it’s a phrase, be sure to replace the underscores with spaces before showing the prompt. Your program should correctly display “a” or “an”, depending on whether the first letter of the prompt word or phrase is a vowel.
The program will Python Programming代写
- Ask the player to enter the name of the Mad Lib textfile
- Ask the player to enter y or nto enter new responses or use the most recent ones.
- Ask the player for responses, replacing underscore characters in bracketed wordswith spaces
- Replace each word or phrase in square brackets with the player’s
- Write the responses to a text file named (whatever the name of the Mad Lib file is)with _responses appended to the name, and then the .txt extension
- Count and print on the screen, the number of words added to the responsesfile
- Write the merged story to a text file named (whatever the name of the Mad Lib file is) with_merged appended to the name, and then the .txt Python Programming代写
- Write the merged story to thescreen
- Convert the filename entered to lowercase
- Convert the y/n response to lower case beforechecking
For example, if your Mad Lib file is madlib.txt, your program will create two text files:
- The file txtwill contain the responses
- The file txtwill contain the Mad Lib story with the responses replacing the prompts in brackets Get this much done first.Python Programming代写
Crazy Mad Libs Python Programming代写
Here’s the crazy part. For each word in the madlib.txt file and for each response to a prompt the player types, that contains the second letter of the story’s title, reverse that word in the output. For example, if the title is Humpty Dumpty, and a word in the story or a response from the player is computer, you would output the word retupmoc (computer reversed) instead.Python Programming代写
Add the “crazy” part to your program next. (Save a copy of the “Mad Libs” part first, just in case you need to revert to a working program.)
In a Box Python Programming代写
Here’s the in a box part. Display the resulting Mad Lib in a box, that is surrounded by a line of asterisks at the top and bottom, and an asterisk and space to the left before each line, and as many spaces as necessary and an asterisk at the right of each line. Center the title as the first line of the box, with an asterisk before and after. The width of the box is dependent upon the length of the longest line of the story after the prompts are replaced with responses.Python Programming代写
Add the “in a box” part to your program next. (Save a copy of the “Crazy Mad Libs” part first, just in case you need to revert to a working program.)
The output of the program follows.
Welcome to Mad Libs
Enter the madlib file name as in madlib.txt: madlib.txt Enter New Answers? (y/n)y
Enter a noun: computer
Enter a season of the year: summer Python Programming代写
Enter a government official: President of the United States of America Enter an animal (plural): aardvarks
Enter a government official: Prime Minister Enter a group of people: swimmers
Enter a verb meaning create: assemble
7 lines written to madlib_responses.txt
******************************************************************
- HumptyDumpty *
* *
- ytpmuH ytpmuD sat ona retupmoc * Python Programming代写
- ytpmuH ytpmuD had agreat remmus *
- All the aciremA fo setatS detinU eht fo tnediserP ‘s aardvarks*
- and all the Prime Minister’s swimmers *
- t’ndluoC assemble ytpmuH ytpmuD backtogether *
* *
* *
****************************************************************** Output saved to madlib_merged.txt
Grading: Python Programming代写
- This assignment will be worth 6 % of your final course Python Programming代写
- The input and output of your program need to appear in exactly the order that is shownin the sample interaction
- Adifferent Mad Lib story will be used when grading the program, so be sure your program follows these
- Your program should compile without syntax errors to receive any credit. If a part of your program is working, you will receive partial credit, but only if the program compiles without syntax errors. As you program, be sure to save intermediate versions of the .py file each time you get a piece of the program running. This way you can always have something tosubmit that works on at least some of the Otherwise, what was working at one point may no longer work after further edits, and you may have no idea how to go back to the previous version (this is all too common!) Python Programming代写
- Name your script as py and upload it to Blackboard by thedeadline.
Points:
This problem has several tasks. Complete as many as you can, or all of them for full credit.
Task Points | |
Replace _ with space in [responses] | 2 |
Replace [prompt] with response | 3 |
Create merged and responses output file names | 5 |
Count number of responses | 5 |
Reverse words containing 2nd letter of title | 10 |
Print resulting Mad Lib in a box Python Programming代写 | 10 |
Correct output and user interaction | 5 |
Code style, readability, comments, approach | 5 |
45 |
更多其他:C++代写 考试助攻 C语言代写 finance代写 计算机代写 物理代写 数学代写 经济代写 java代写 python代写 程序代写 金融经济统计代写 app代写