Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Programming. Assignment Overview Hangman is a popular word game. In this

ID: 3715948 • Letter: P

Question

Python Programming.

Assignment Overview

Hangman is a popular word game. In this game, the player is given some number of blanks

representing the name of a movie or an actor and he/she has to guess the name using at most K

number of chances.

A good website to play this game is :

http://www.hangman.no/. Select English as the language,

then “Play game” and finally choose a category in the list and get started. Here, the number of

chances you get is 10 (i.e. k = 10), for your project it will be only 6.

Task

Your task is to implement the Hangman game in Python. Before implementing the game, please

play the game on the website mentioned above. It would help you understand the project.

Program Specifications:

Output a brief description of the game of hangman and how to play

  Ask the user to enter the word or phrase that will be guessed (have a friend enter the phrase for you if you want to be surprised)

  Output the appropriate number of dashes and spaces to represent the phrase (make sure it’s clear how many letters are in each word and how many words there are)

  Continuously read guesses of a letter from the user and fill in the corresponding blanks if the letter is in the word, otherwise report that the user has made an incorrect guess.

  Each turn you will display the phrase as dashes but with any already guessed letters filled in, as well as which letters have been incorrectly guessed so far and how many guesses the user has remaining.

  Your program should allow the user to make a total of 6 guesses.

Assignment Notes:

If the letter has already been guessed, output a message to the player and ask for input again.

If the guess entered is not an alphabetic letter, output a message and ask for input again.

If the letter is present in the word to be guessed, fill in the blanks appropriately with this particular letter.

If the complete name has been guessed, the game is over - player wins the game.

Output a message telling the player they have won and quit the game.

If the letter/digit is not present in the word to be guessed:

Give a message to the player indicating that the guess is incorrect and remaining number of chances is one less.

If remaining number of chances is 0 (zero), the game is over - player loses the game.

Output a message that they have lost and what the correct word was.

Quit the game.

Deliverables

The deliverable for this assignment is the following file:

            Lastname_Firstname_11.py – the source code for your Python program

Tips/Hints:

This project can all be done with strings, use help(str) in the python shell window to see all of the

string methods that may be useful. Some of the ones I used in the example program are below:

1) The string concatenation operator “+”. In order to keep track of the incorrect guesses, you

could initialize a blank string and use “+” to update the string with the incorrect guesses.

2) The membership operator “in” would be useful to check if a particular letter/digit has already

been guessed (correctly or incorrectly).

3) String slicing is useful to insert a letter in a string. For example if I have x = “hello” and I

wanted to put a ‘Z’ in the middle of the word, I could write:

x = x[0:3] + ’Z’ + x[3:]

or if I wanted to ‘Z’ to replace the ‘e’ I could write:

x = x[0:1] + ‘Z’ + x[2:]

remember string indexing using slices includes the start position but not the end position, so

x[0:2] is “he” but does not include the ‘l’ at index 2.

4) lower() can be used to change a string to lowercase – make sure you find the letter the user

enters whether it’s lower or uppercase in the guess word.

5) find() returns the index at which the first instance of a substring is found in a string, for

example if x=”hello”

x.find(‘e’) returns 1 and x.find(‘l’) returns 2.

6) Remember if there is an apostrophe (‘) or a dash (-) in the original phrase you should output it

instead of a dash, the user doesn’t have to guess those.

7) Try the example program with many different inputs and make sure your program behaves

similarly!

Sample output of the program

Explanation / Answer

//Below i had written code for hangman and it is working fine.

Hope this helps...

Thankyou... :)