CSC108H Assignment 1: Phrase Puzzler

Deadline: Tuesday 03 October 2017 by 9:00pm

A warning about academic offenses

All of the work you submit must be done by you, and your work must not be submitted by someone else. Plagiarism is academic fraud and is taken very seriously. The department uses software that compares programs for evidence of similar code. Please read the Rules and Regulations from the U of T Governing Council (especially the Code of Behaviour on Academic Matters). Please also see the information for students from the Office of Student Academic Integrity.

Please don’t copy. We want you to succeed and are here to help. Here are a couple of general guidelines to help you avoid plagiarism:

Phrase Puzzler

In this assignment, you'll be writing a Phrase Puzzler game. To see how the game is played, please watch the demo below.

The video demonstrates playing the one-player version of the game, but your code will eventually also have a two-player human vs. human version and also a human vs. computer version.

This assignment is meant to give you practice working with strings, functions, and if statements.

Starter code

For this assignment, we are giving you some files, including some Python starter code files. See the Downloads section below for instructions on how to get the files.

There are two starter code files:, which contains the main program, and You'll need to add the functions described below to the file. Do not modify the file The main program depends on functions you will write, so this program won't run properly until you've implemented the functions.

We are also providing two files that contain puzzle phrases: puzzles_small.txt and puzzles.txt. The puzzles used in the Phrase Puzzler game will never involve uppercase characters.


Constants are special variables whose values do not change once assigned. A different naming convention (uppercase pothole) is used for constants, so that programmers know to not change their values. For example, in the Phrase Puzzler starter code, the constant VOWEL_PRICE is assigned the value 1 at the beginning of the module and the value of VOWEL_PRICE should never change. When writing your code, if you need to refer to the price of a vowel, you should use VOWEL_PRICE, rather than 1. The same goes for the other constant values.

Using constants simplifies code modifications and improves readability. If we later decide to use a different vowel price, we would only have to change the price in one place (the VOWEL_PRICE assignment statement), rather than throughout the program.

Some notes about the Phrase Puzzler program:

When you run, one of three game types (a one-player, a two-player human vs. human version, or a two-player human vs. computer version) is played. Before you can play each of the three game types, you'll need to implement the following functions:

See the table below for a description of these functions.

Files to Download

Please download the Assignment 1 Files and extract the zip archive. The following paragraphs explain the files you have been given.

Starter code:

This file contains some constants, and a complete docstring (but not body!) for the first function you are to write. You will update this file to include the complete functions that you write. When you have written all of the functions, you may try playing the game with more challenging puzzles by changing the constant DATA_FILE to 'puzzles.txt'!

Starter code:

This file contains the main program and when it is run, the functions that you wrote and put in the file will be called. Do not make any changes to the file.

Data: puzzles_small.txt and puzzles.txt

These files contain Phrase Puzzler puzzles.


We have provided a checker program that you should use to test your code. See below for more information about

What to do

In the starter code file, complete the following function definitions. Use the function design recipe that we have been learning in class, and write complete docstrings for each function.

We have included the type contracts in the table; please read through the starter code to understand how they will be used.

Function name
(Parameter types) -> Return type
is_win(str, str) -> bool The first parameter represent a puzzle and the second represents its view. Return True if and only if the puzzle is the same as the view. (Please note: we have provided the complete docstring for this function as an example.)
game_over(str, str, str) -> bool The first parameter represents a puzzle, the second represents its view, and the third represents the current selection (one of CONSONANT, VOWEL, SOLVE, or QUIT). Return True if and only if the puzzle is the same as the view or the current selection is QUIT.
bonus_letter(str, str, str) -> bool The parameters represent a puzzle, its view, and a letter to evaluate. Return True if and only if the letter appears in the puzzle but not in its view.
update_letter_view(str, str, int, str) -> str The first parameter represents a puzzle, the second represents its view, the third represents the index of the character to update, and the fourth represents the letter that has been guessed. Return a single character string representing the next view of the character at the given index. If the character at that index of the puzzle matches the guess, then return that character. Otherwise, return the character at that index of the view.
calculate_score(int, int, str) -> int The first parameter represents the current score, the second represents the number of occurrences of a letter in the puzzle, and the third represents whether that letter is a CONSONANT or VOWEL. Return the new score by adding CONSONANT_POINTS per occurrence of the letter to the current score if the letter is a consonant, or by deducting the VOWEL_PRICE from the score if the letter is a vowel.
next_player(str, int) -> str The first parameter is the current player (one of PLAYER_ONE or PLAYER_TWO) and the second is the number of occurrences in the puzzle of the letter last chosen by the current player. If and only if the number of occurrences is greater than zero, the current player plays again. Return the next player (one of PLAYER_ONE or PLAYER_TWO).

No Input or Output!

Your file should contain the starter code, plus the function definitions specified above. must not include any calls to the print and input functions. Do not add any import statements. Also, do not include any function calls outside of the function definitions.

How should you test whether your code works?

You should test each function individually by writing code to verify your functions in the Python shell. For example, after defining function is_win, you might call it from the shell (e.g., is_win('e-mail inbox', ^-m^il i^^^^')) to check whether it returns the right value (False). One call usually isn't enough to thoroughly test the function — for example, we should also test is_win in cases where it should return True.

Once you've checked each function individually, play the game using the starter code to see whether it works as expected. If not, go back to testing the functions individually.

CSC108 A1 Checker

We are providing a checker module ( that tests two things:

To run the checker, open and run it. Note: the checker file should be in the same directory as your, as provided in the starter code zip file. You can find a demo of the checker being run in the Week 3 Prepare exercises on PCRS.

If the checker passes:

If the checker fails, carefully read the message provided:

Make sure the checker passes before submitting.


These are the aspects of your work that may be marked for A1:

What to Hand In

The very last thing you do before submitting should be to run the checker program one last time. Otherwise, you could make a small error in your final changes before submitting that causes your code to receive zero for correctness.

Submit on MarkUs by following the instructions on the course website. Remember that spelling of filenames, including case, counts: your file must be named exactly as above.