# CSCI 141 Assignment 3: Conditionals and Loops solution

\$30.00

Original Work ?

5/5 - (1 vote)

## Guessing Game: 32 points

Assume you are a computer programmer working for a company, Nostalgia-R-Us, that makes
legacy (old-style, text-only) games for people who were using computers in the early 1980s.

The game you have been tasked to write is a simple guessing game. A player specifies how
many tries are allowed, and then proceeds to guess a secret two-character sequence. Because
the game is intended for distribution to alumni of Western Washington University, the letters
are selected from the letters in the word bellingham. See the sample screen shots in Figure 1
for sample gameplay.

Figure 1: Two sample runs of the program

Your manager has provided you with the following requirements and/or pseudocode:
• Your program must be named letterGuessGame.py.
• The program should provide a brief blurb that explains the game and prompts the player
to specify the number of tries.

• Two letters from the word bellingham should be chosen randomly as the secret answer.
Because the letters are chosen independently, both the first and second secret letters may
be the same.

• While the player has tries remaining, the game should prompt the user to guess a letter.
For each of the two secret letters, the program should specify whether the guess was
correct or not. If the guess is not one (or neither) of the secret letters, then the program
should output a statement stating that fact.

• The program should remember which letter(s) (if any) have already been guessed correctly.
Once a letter has been guessed correctly, subsequent output should not mention that letter.
• If the player guesses both letters, the game should output ”You win” and terminate right
away, even if the player has tries remaining.

• If the player does not correctly guess the secret letters in the number of tries indicated,
the game should end, specify that there are no more tries remaining, and the correct

This game can be implemented many different ways. Declare and use as many variables as you
need to keep track of guesses. The logic for a sample ”you lose” game play is shown below.
Num Guesses : 4
User Guess 1 : b

Game Response : You have guessed the first leter. The second letter is not b.
User Guess 2 : g
Game Response : The second letter is not g.
User Guess 3 : l
Game Response : The second letter is not l.
User Guess 4 : e

Game Response : You are out of tries. Game over. The secret letters were b and h.
2.1 Testing
Test your program thoroughly. Make sure it works correctly for a ”win” and a ”lose” scenario,
noting that a player can win after a minimum of 1 attempt (if both letters are the same and the
player guesses them on the first try) but can also win in more than that, up to (and including)
the maximum number of attempts specified.

Submission

Rubric
Canvas (written) questions 18 points
The program correctly prompts for the number of tries 2
The program selects two random characters from the letters in bellingham 4
The program correctly keeps track of how many tries are remaining 4
The program specifies which (if any) of the secret letters have been guessed
correctly after each guess

If one of the two letters has been guessed correctly, on subsequent guesses, the
program does not mention the already-guessed letter

The program terminates right away and says ”Win” if the player guesses correctly.
If the player loses, the answer is revealed.
5
The program runs as intended, and does not generate errors 5
The code is commented adequately and variable names are appropriately named 2
Total 50 points

3 Challenge Problem
This challenge problem is worth two points of extra credit: Write a program that prompts the
user for a non-negative decimal number, then prints the binary representation of the number