PA2 - 00000111 Little Words (Loops and Lists)

Due Dates and Submission Details

See submission details below for all due dates and submission details. Note there are multiple submission parts.

Honor Code

This assignment should be completed individually to maximize learning. It is important that you adhere to the JMU Honor Code.


  • Write loops that contain nested if-else statements.
  • Write loops for contexts that are appropriate for both while and for structures.
  • Pass arrays as method arguments and return values.
  • Manipulate, initialize, copy and compare elements of list of Strings.
  • Practice using tools such as style and Unit Testing.


In this program, you will implement a simplified text version of the 7 Little Words — game. (For those of you who may not know, 00000111 interpreted as a base 2 number is 7 in base 10.) The 7 Little Words website explains the game and will allow you to play it. Our text version is very similar, but breaks every solution word into only two pieces, then displays those words in text boxes vertically instead of as a graphical grid. Our version does not give the hint of how many letters a solution is but otherwise works very similar to the game on the website. The clues must be solved in order and the user can ask for multiple hints for each clue. Hints can be the first letter of the solution, the first "slice" or part of the solution word in the puzzle, or the whole word.


You will be writing two files for this assignment, and and one test file, The functions for the first two files is described below. Note that each function must be implemented exactly as described. See the example input and output below for the form of the interaction with the user.

  • prompt_for_string(message, min)

    This function will prompt the user using the message(String) passed to it, read in the user's response as a String from user input and then return the response as a String. If the user enters a string with a length (number of letters/char) strictly less than the length indicated by min(int), then they will be reprompted.  The return value should be a valid string once finally entered of length min.

    Example: terminal_ui.prompt_for_string("Enter string", 2) where the user enters "m" would reprompt until a longer word is entered. If the first string of 2 or more letters the user enters is "magnetism", the string returned will be magnetism. Note that if quotes are included in the user's entry they will be included in the String returned by the function. Below is an example from running terminal_ui_driver.

        Enter string: m
        Enter string:  
        Enter string: magnetism
        Your string was magnetism
  • prompt_for_int(message, max)

    This function will prompt the user using the message passed to it, read in the user's response as an integer from user input then return the response as an int. If the user enters an integer that is strictly less than one or greater than max, then they should be reprompted for a new integer.  The return from the function should be the valid int up to max size.

    Example: terminal_ui.prompt_for_int("Enter integer 1-12", 12) where the user enters 0 would reprompt until an integer between 1 and 12 inclusive is entered. If the first number the user enters that is within the range 1-12 is 12, the int returned will be 12. Below is an example from running terminal_ui_driver.

        Enter integer 1-12: 0
        Enter integer 1-12: 13
        Enter integer 1-12: 12
        Your integer was 12
  • prompt_n_display_hints(solution)

    This function will prompt the user to see if they want a hint as described below, then print out the correct hint, reprompting as long as the user asks for a proper hint. If the user enters an "n" or any other response than a proper hint, the prompting stops.

    Example: terminal_ui.prompt_n_display_hints("magnetism") where the user enters each kind of hint in order, would display each hint in order. Below is an example from running terminal_ui_driver.

          Want a hint? Enter
          "f" for first letter
          "s" for first slice
          "w" for whole word
          "n" for none: f
          Want a hint? Enter
          "f" for first letter
          "s" for first slice
          "w" for whole word
          "n" for none: s
          Want a hint? Enter
          "f" for first letter
          "s" for first slice
          "w" for whole word
          "n" for none: w
          Want a hint? Enter
          "f" for first letter
          "s" for first slice
          "w" for whole word
          "n" for none: n

  • word_splicer(solutions)

    This function will split each of the words of the solutions array in half. If the word has an odd number of characters the smaller piece will be the first slice and the longer the second slice. A "board" list of half words will be returned. board list will have twice as many elements as the solutions list and the first two elements will be the two halves of first solution word, the third and fourth elements the two halves of the second solution word, etc. Note that this function should return null if the solutions list is null or of zero length. If there are words in the solutions list they will be a minimum of two letters (char). The algorithm used for this section should work with any reasonable size solutions list.

    Example: generator.word_splicer(["tofutti", "magnetism"]) would return ["tof", "utti", "magn", "etism"].

  • clue_to_string(clues)

    This function will create a string that will print out the clues. Each clue should be on it's own line with the user referenced number (i.e. first element is 1 as opposed to 0), followed immediately by a ')', followed by a space, and then the clue. If the clues list is null or empty, the function should return the empty string ("").


    Example:  generator.clue_to_string(["a small bird", "common flavor"]) 
    would return "1) a small bird\n2) common flavor\n".


  • board_to_string(board)

    This function will create a string that will print out the board. Each slice should look like it is in a box. Each slice will be preceded and followed by a line of dashes as long as the slice plus an additional 9 dashes. The line with the slice will be as follows: a |, followed by a space, followed by the user referenced number (i.e. first element is 1 as opposed to 0) formatted as two digits, followed by a space, followed by |, followed by a space, and then the clue, followed by a space and then a final |.


    Example:  generator.board_to_string(["tof", "utti"]) would return 
    "------------\n| 01 | tof |\n------------\n-------------\n| 02 | utti |\n-------------\n".



This assignment requires you to use both of the testing techniques you have learned so far. should be tested first using and and test.exp files. The driver code is provided for you below along with one test. should be tested using Unit testing. Note that the examples given in the function explanations above are provided in the Unit test below. Don't forget to include tests for invalid inputs as described for each function.

You should test terminal_ui with several of your own tests, but included here is a and a pa2TUItest1.exp to give you one verified command-line test.

This can be tested in command line as such:

chaoaj@IT-22-0361-M 7littlewords-student % python < > pa4TUItest1.out
chaoaj@IT-22-0361-M 7littlewords-student % diff pa4TUItest1.exp pa4TUItest1.out                           
chaoaj@IT-22-0361-M 7littlewords-student % 

Below is a set of tests you may find helpful for testing

 self.assertEqual(["tof", "utti", "magn", "etism"],
generator.word_splicer(["tofutti", "magnetism"]), "Error in test1: word_splicer")

self.assertEqual("1) a small bird\n2) common flavor\n",
generator.clue_to_string(["a small bird", "common flavor"]),"Error in test1: clue_to_string")
actual_board = generator.board_to_string(["tof", "utti"])
self.assertEqual("------------\n| 01 | tof |\n------------\n-------------\n| 02 | utti |\n-------------\n",
actual_board, "Error in test1: board_to_string")

Playing the Game

When all of your methods are working you can test to see if you can run the file to play a round of the game. Here's a sample output.txt from my run of Tues Oct 23rd Daily puzzle.


This assignment has two parts that should be completed in order. By the first deadline you should read this specification document and take the readiness quiz.   By the second deadline you must submit your completed code for and,  through Gradescope.

Part A 

See your Canvas section for due dates / late submission policy.  Read this document and complete the readiness quiz for PA2 in Canvas.  This submission cannot be late!. You must submit by the deadline to get any credit.

Part B

Read this entire document and complete the code for, files through Gradescope

  • See your Canvas section for your class for due dates / late submission policy

Just implement the above in python, creating files called, and Before uploading your files, be sure to complete carefully complete the steps below. If you are having trouble getting started, see the Hints section further below.

    • Verify that your code is working. You should test it with several tests. 
    • Make sure that all your variable names make sense and you are following coding conventions.
    • Check that you have inserted the proper DocString `Author` and `Version` comments in the appropriate header.
    • Run pep8 style and eliminate ALL warnings about your code.


Your submission will be graded using the following criteria:

Requirement Points
PART A: Readiness Quiz 10
PART B: Style/DocString 5
PART B: Instructor grading based on style, code quality, comments. 10
PART B: While/do-while context loop (prompt_for_string, prompt_for_int, prompt_n_display_hints) 18
PART B: Use nested loops (board_to_string) 7
PART B: other functions 10

Don't put off submission until the last possible minute! Any submission system may become bogged down when it receives a large number of submissions. You may have some unanticipated difficulties uploading your code. It is your responsibility to take these possibilities into account and submit early enough to ensure that the submission process is completed before the deadline. It is recommended that you submit once early, after you have a set of stubs completed, to make sure that you have all of the method and class definitions exactly right.


It would be wise to implement the code in the following order.

    1. Implement prompt_for_int in terminal_ui. Test it using your own main or the interactions pane in Thonny and make needed changes.
    2. Implement prompt_for_string in terminal_ui. Test it using your own main or the interactions pane Thonny and make needed changes.
    3. Test prompt_for_int and prompt_for_string only using the terminal_ui_driver code by using a stub for prompt_n_display_hints. Make needed changes.
    4. Implement and test prompt_n_display_hints using the Make needed changes.
    5. Finalize code and check style then submit to Gradescope.


This assignment was originally designed by Dee Weikle and Alvin Chao.

Back to Top