CSCI 102 - Intro to Computer Science LAB

Python Assignment

Extra Credit

Quick Links: zyBook | AutoGrader | Piazza | Canvas | CS @ Mines

Home | Contact | Schedule | Assignments | Syllabus |

Extra Credit Python Assignment
Due by Tuesday, October 26th, 2021
        Hangman (must upload to Gradescope by 11:45pm)


Welcome to your extra credit python assignment! This lab is to be done on your own (not pair programming). Since this is an extra credit lab, it will not be demoed in class on Tuesday. However, it must be submitted to Gradescope no later than 11:45PM on the due date.

Hangman (5 points extra credit)

Introduction

To get started, open IDLE and create a New File via the File menu. We suggest you immediately save this file in the directory managing all your 102 Python Labs this semester. Please save this file with the following name: ExtraCredit-hangman.py.

Problem Statement

In this lab we will combine several of the fundamentals that we have learned so far, including strings, conditionals, branching, variables, lists, and while loops. The goal is to build a simple Hangman game. Your program needs to ask the user to enter a secret word and the number of guesses allowed for the game. Your program should then enter a loop to play the game. We suggest you structure your program as follows:
  • Prompt the user for the secret word
  • Prompt the user for the number of guesses allowed in the game
  • Begin Game:
    • While the word hasn't been guessed and the number of guesses is less than the number of guess allowed:
      • Prompt the user for a character
      • Increment the number of guesses
      • Check to see if the guessed character appears in the secret word
        • If the secret word has been guessed, print "Congratulations! You guessed the secret word!". Then print the secret word on a new line and end the game.
        • If the secret word has NOT been guessed and the player has no more guesses left, print "You ran out of guesses! Better luck next time!" Then print the secret word on a new line and end the game.
        • If the game isn't over AND the character appears in the word, print out "Success! You guessed a character in the word!". Then print the current status of the secret word on a new line.
        • If the game isn't over AND the character doesn't appear in the word, print out "Boo! You guessed incorrectly". Then print the current status of the secret word on a new line.
        • Note, if the user guesses a character that has already been guessed (regardless of if that character was or was not in word), you should print "Boo! You guessed incorrectly." Then print the current status of the secret word on a new line.
        • Hint: Maybe have a list of letters that have been guessed, which is checked before you look for the letter in the secret word. Or maybe use an uncommon character (like #,$,^, or @) in the secret word that has been guessed. There are many ways to solve this problem. Think creatively!

Lab I/O Format

Throughout this semester we will use a specific Lab Input/Output Format. This format is described below:
  • When prompting for input, use the prompt string WORD>, where WORD is a single, uppercase word which describes the input. For example, this lab might choose: WORD>, NUM>and CHAR>.
  • When providing output that will be graded, start the line with OUTPUT. Think of this as "boxing your answer" on a math worksheet; it lets us quickly find your answer. Our grading script will skip any output lines that do not start with OUTPUT.
  • You are welcome (and should!) have other output lines that do not begin with OUTPUT; while our grading script will ignore these, good programmers include print statements that are informational to the user of the program.
  • A submission without exactly correct output formatting will recieve an AUTOMATIC ZERO. This is because Gradescope is automated - it does not look at your code, only the results, and thus the format of the results must be consistent for all students.

Example Execution #1

Welcome to Simple Hang Man
Enter a secret word:
WORD> animal
Enter the number of guesses allowed:
NUM> 40
Please enter a character:
CHAR> a
OUTPUT Success! You guessed a character in the word!
39 guesses remaining
Character's guessed: [ a ]
OUTPUT Secret word: a _ _ _ a _

Please enter a character:
CHAR> n
OUTPUT Success! You guessed a character in the word!
38 guesses remaining
Character's guessed: [ a, n ]
OUTPUT Secret word: a n _ _ a _

Please enter a character:
CHAR> e
OUTPUT Boo! You guessed incorrectly
37 guesses remaining
Character's guessed: [ a, n, e ]
OUTPUT Secret word: a n _ _ a _

Please enter a character:
CHAR> i
OUTPUT Success! You guessed a character in the word!
36 guesses remaining
Character's guessed: [ a, n, e, i ]
OUTPUT Secret word: a n i _ a _

Please enter a character:
CHAR> m
OUTPUT Success! You guessed a character in the word!
35 guesses remaining
Character's guessed: [ a, n, e, i, m ]
OUTPUT Secret word: a n i m a _

Please enter a character:
CHAR> l
OUTPUT Congratulations! You guessed the secret word!
34 guesses remaining
OUTPUT Secret word: a n i m a l

Example Execution #2

Please enter a character:
CHAR> f
OUTPUT Boo! You guessed incorrectly
1 guess remaining
Character's guessed: [ a, o e, t, t, l, d, q, r ]
OUTPUT Secret word: a _ _ _ a l

Please enter a character:
CHAR> z
OUTPUT You ran out of guesses! Better luck next time!
OUTPUT Secret word: a n i m a l

Gradescope Submission Nuances

Since this is an extra credit lab, you will not demo this lab in class on Tuesday. However, you must submit it to Gradescope no later than 11:45PM on the due date.

Comments

All Python files should include a header with your name, section, assignment info, references (i.e., who did you collaborate with on this assignment?; what resource did you use?), and approximate time taken to do the assignment. . Be sure to cite any allowed external references used to complete the assignment. Any code without this header will lose 1 point. Here's an example:
        #  Tracy Camp
        #  CSCI 102 – Section A
        #  Extra Credit Lab - Hangman
        #  References: Used website to get more familiar with 2D lists
        #  References: https://snakify.org/en/lessons/two_dimensional_lists_arrays/
        #  Time: 45 minutes

Submit Solutions

Follow these steps to submit your file to Gradescope.
  • In Gradescope, go to CSCI 102 > Assignments and upload ExtraCredit-hangman.py.
To receive full credit, your code must execute in Python 3, and you must submit a single file for each portion of the assignment (your Python code file). In addition, your code must follow the Lab I/O Format.

Whenever you submit something to Gradescope, we strongly recommend you always double check what you submitted actually got submitted correctly (e.g., did the file upload correctly? did you submit the correct file? etc.) If your submission is incorrect, it's on you.