Python代写:CS521 Mad Libs

代写一个Mad Libs的填词游戏,根据不同的输入生成不同的文章。

Purpose

In this assignment, you will be demonstrating your understanding and use of python constructs, as covered in module 1.

Assignment Background

This assignment involves the game Mad Libs. Mad Libs is a game which has text missing some types of words such as verbs, nouns, adjectives etc. Here is a basic example of a multiple line mad lib:

Man verb on a adjective noun.
Noun verb to the adjective ground.
All the king's adjective horses and all the king's dainty noun could not verb scrambled egg man back together again.

Example word lists:

1
2
3
NOUNS = ["time", "year", "people", "way", "day", "man", "thing", "woman"]
VERBS = ["pay", "put", "read", "run", "say", "see"]
ADJECTIVES = ["other", "new", "good", "high", "old"]

Assignment Statement

  • You can either choose to use the example or create your own mab lib.
  • We provide you with examples of lists that you use or you may create four lists of your choice.
    • 1 for nouns
    • 1 for verbs
    • 1 for adjectives
    • 1 for sentences (with missing words)
  • The lists must be of different lengths. For example, nouns list has 4 items, other lists have more or less than 4 items. Only one list can have a given length.
  • The lists should be < 10 items long.
  • Each sentence should be missing 1 element of each type (noun, verb, adjective).

The file__init__.py is blank and should not be modified. You are required to supply Last Name_First Name_Assignment1.py. In this assignment, you will accomplish the following:

Requirements

  1. Prompt user for a number.
  2. Validate user input for the following:
    • a. Numbers are positive
    • b. Numbers are integers (Not floats)
  3. The user input will be used to retrieve from each of your lists.
    • a. Get 1 sentence from the sentence list.
    • b. Get 1 noun from the noun list.
    • c. Get 1 verb from the verb list.
    • d. Get 1 adjective from the adjective list
      Hint: Watch out! The user input could be larger than the number of elements in the list
  4. Insert the selected noun, verb and adjective into the selected sentence.
  5. Check that the resulting sentence is unique (has not been used before).
    • a. If it has not been used before, save it in the list of completed sentences (your mad lib)
    • b. If it has been used before, do not save it and print message letting the user know.
  6. Print your current mad lib to the user (list of all completed sentences so far)
  7. Ask user if he/she wants to keep playing (ans: y or n)
    • a. Validate user input
    • b. If “y” go back to 1
    • c. If “n” exit

Code/Comment Format

Good code includes well named variables that are consistent from the beginning to the end of the program. Naming of objects should be self-explanatory. For instance, iterator_for_noun_list is much better than i.
Every program consists of a sequence of paragraphs, each of which has objectives, and which builds on the previous paragraphs. We are mostly interested in objectives that are valid at the end of the program so we can verify the program’s design. The following is a preferred form for such paragraph headings. The # sign is adequate when the comment is a single line.

#This is an in-line comment - used to document the code for you, or anyone else, that intends
#To extend the code

In-line comments are helpful when one has to go back to the code 6 months later to make changes.
For doc strings, python allows the use of triple quotes. The triple quotes can be either single or double quotes. A doc sting is generally used as user documentation. It does not need to include details of the implementation of the program, but instead it provides documentation as how to use the API for the program (input, output etc.)
For example:

1
"""

This is an example of a doc string
It allows multiple lines within the string.

1
2
"""
'''

This is an example of a doc string
It allows multiple lines within the string.

1
'''

This becomes significant when using functions, classes etc. as the triple quotes help to selfdocument the parameters and return values of the function.
Provides a good guide to code with in Python. You are not required to use it, but whatever style you choose must be consistent throughout. https://www.python.org/dev/peps/pep-0008/

What to Deliver

Supply The Last Name_First Name_Assignment1.py file (the __init__.py file is attached and should be left as is).

Notes

  • Assignments can be submitted once. If extenuating circumstances exist, contact your facilitator.
  • Note the statement in the syllabus on timeliness of submissions (the gist being that all assignments must observe the deadlines).
  • Start by identifying and ordering the objectives.
  • There are no testing requirements for this assignment. However, it would be prudent to make sure your program does not crash and all input validation is performed correctly.