Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Mad Libs Assignment

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:

NOUNS = ["time", "year", "people", "way", "day", "man", "thing", "woman"]

VERBS = ["pay", "put", "read", "run", "say", "see"]

ADJECTIVES = ["other", "new", "good", "high", "old"]

Example of generated sentences:

Man put on a other people

woman read to the high ground

Requirements:

  1. Setup 4 lists. We provide you with examples of lists that you can use or you may create four lists of your choice.
    1. 1 for nouns
    2. 1 for verbs
    3. 1 for adjectives
    4. 1 for sentences template. Each sentence template should be missing 1 element of each type (noun, verb, adjective).
    5. The lists must be of different lengths. For example, nouns list has 4 items, other lists have more or less than 4 items.
    6. The lists should be < 10 items long.
  2. Prompt user for single number.
    1. Validate user input for the following:
      1. Number is positive; greater than 0
      2. Number is an integer number (Not float/letter or bool)
  • Input is not empty
  1. One number is used to access all lists regardless of the size of the list.
  2. The user input must be able to index all elements of any list including index 0. Mod should be used to accomplish this.
  1. The user input, after mod operation for each list length, will be used to retrieve from each of your lists.
    1. Get 1 sentence template from the sentence list.
    2. Get 1 noun from the noun list.
    3. Get 1 verb from the verb list.
    4. Get 1 adjective from the adjective list
  2. Insert the selected noun, verb and adjective into the selected sentence template using format().
  3. Check that the resulting sentence is unique (has not been used before). A sentence is considered unique if the whole sentence has not been used before.
    1. If the sentence is unique, save it in the list of completed sentences (your mad lib)
    2. If the sentence has been used before, do not save it and print message letting the user know. It is up to you whether you terminate the program or allow the user to re-enter input. Either way, you have to print a message to the user indicating what happened.
  4. Print the current mad lib to the user (list of all completed sentences so far, one sentence on its own line).
  5. Ask user if they want to keep playing.
    1. Validate user input – Valid input is (y, Y, yes, Yes, n, N, No, no)
      1. If invalid, you can either retry or exit.
    2. If “y” go back to 2
    3. 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:

“””

This is an example of a doc string

It allows multiple lines within the string.

This is an example of a doc string

It allows multiple lines within the string.

This becomes significant when using functions, classes etc. as the triple quotes help to self-document the parameters and return values of the function.

Sample Output

Please enter an integer greater than zero: 0

Oops! That integer is not > 0. Try again...

Enter 'y' to continue playing and 'n' to exit: y

Please enter an integer greater than zero: 20

"This day may read some other advice." added to your madlib

This day may read some other advice.

Enter 'y' to continue playing and 'n' to exit:

Enter 'y' to continue playing and 'n' to exit: y

Please enter an integer greater than zero: 2

"You read must the good people." added to your madlib

This day may read some other advice.

You read must the good people.

Enter 'y' to continue playing and 'n' to exit: y

Please enter an integer greater than zero: 20

Error: "This day may read some other advice." already in your madlib

This day may read some other advice.

You read must the good people.

Enter 'y' to continue playing and 'n' to exit:

Enter 'y' to continue playing and 'n' to exit:

Enter 'y' to continue playing and 'n' to exit:

Enter 'y' to continue playing and 'n' to exit:

Thank you for playing madlib; here are your 2 madlib sentences

This day may read some other advice.

You read must the good people.

Process finished with exit code 0

Copyright © 2009-2023 UrgentHomework.com, All right reserved.