Need help on hangman game on python

Reply

Join Date: Oct 2009
Posts: 3
Reputation: henks83 is an unknown quantity at this point 
Solved Threads: 0
henks83 henks83 is offline Offline
Newbie Poster

Need help on hangman game on python

 
0
  #1
27 Days Ago
I have no idea how to do this. Please help.

This week's lab is to design a hangman game. Your program should be able to open a text file which contains a list of words (one word on each line of the text file) and read the words into a list to contain all of the possible words.

Your program should then prompt the user to play a game, please provide at least 3 difficultly levels for the user to choose from. (Difficulty applies to the number of wrong answers allowed before the user loses the game)

Once the user has selected a difficulty, a word from the word list should be chosen randomly using python's random library (example of how to use random at bottom of assignment page).

The program should then display stars to screen so the user knows how many letters are in the word (I suggest making a list of stars). Then the user should be prompted for a guess. After each guess, the program should determine if the guess is valid (ie, it should check to see if the guess has been used before....This means you will need to keep track of what letters have been guessed). If the guess is invalid, a message should be displayed telling the user that they have already guessed that letter and prompting the user to try another letter. If the guess is valid, the program should check to see if the letter is in the word.

If the letter is in the word, the list containing stars should be updated so that correct letters are displayed where required. If the letter is not in the word, then the user should be credited with an incorrect guess.

After the guess has been evaluated, a hangman picture should be displayed (based on number of wrong answers and difficulty level...You may use ASCII art or turtle graphics for the picture), the list of incorrect guesses, and current status of the word. The pattern of guessing should continue until the user is able to correctly solve the puzzle, or is "hung" (runs out of incorrect guesses).

Once the game is complete, the user should be asked if they wish to play again. Example of a working hangman game to be demonstrated in lab.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 105
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 9
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
0
  #2
27 Days Ago
It seems like so many people come on to the forums requesting for home works assignments they have no idea on how to do. Does your teacher realize that you don't have the proper skills to do this? Or maybe you do know you just don't want to work. This just involved a bunch of lists and loops.

First of all, I suggest making a function for each frame if you're going to do ascii. Then it will make it easy to call each frame up. The main game should be held in a while loop. Here's a code example of how it might look.

  1. def frame1():
  2. print ("art")
  3.  
  4. while True:
  5. if NumberWrong == 3:
  6. frame1()
Last edited by AutoPython; 27 Days Ago at 12:20 am.
To P(ython), or not to P(ython)
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,001
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 284
woooee woooee is offline Offline
Veteran Poster
 
0
  #3
27 Days Ago
This week's lab is to design a hangman game. Your program should be able to open a text file which contains a list of words (one word on each line of the text file) and read the words into a list to contain all of the possible words.
If you don't know how to open and read a text file, then look at one of the online tutorials like here http://effbot.org/zone/readline-performance.htm Then get the input from the user, etc. Finally, post the code here that you are not able to complete.

It seems like so many people come on to the forums requesting for home works assignments they have no idea on how to do
This seems to be this year's excuse to get someone else to do it for you. Last year it was "I Googled for hours and can't find the answer". Next year it will be something else.
Last edited by woooee; 27 Days Ago at 12:57 am.
Linux counter #99383
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 188
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 45
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Junior Poster
 
0
  #4
27 Days Ago
hi
first try to solve the problem yourself and then if you are stuck at some point post your code here and we'll be happy to help. At least try to show some effort before giving up so easily It would be much more helpful if you solved the problem rather than someone else posting their solution here.
Try to make a plan of what things to do first, set up the main functions and use them in the game loop
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: henks83 is an unknown quantity at this point 
Solved Threads: 0
henks83 henks83 is offline Offline
Newbie Poster

So far

 
0
  #5
26 Days Ago
import random
game = ['hangman']
star = '*'
play = raw_input("Do you want to play Hang Man? ")
difficulty = raw_input("Easy, Medium, or Hard difficulty? ")
guess = raw_input("Guess a letter: ")

while play !='n':
if play == 'y':
if difficulty == ("Easy"):
guess * 3
if difficulty == ("Medium"):
guess * 4
if difficulty == ("Hard"):
guess * 5
print star * len(words)
guess
guess = guess.strip()
if guess in words:
print 'Correct'
print star *len(words)
print guess
elif guess == '':
print 'Incorrect'
print star * len(words)
print guess
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: henks83 is an unknown quantity at this point 
Solved Threads: 0
henks83 henks83 is offline Offline
Newbie Poster

difficulty levels

 
0
  #6
26 Days Ago
What do I put for the difficulty levels to change the number of guesses?
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 188
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 45
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Junior Poster
 
0
  #7
26 Days Ago
hi
for the difficulty level you could do something like this

  1. def getDifficultyLevel( i ):
  2. if i == "easy":
  3. return 15
  4. elif i == "medium":
  5. return 10
  6. elif i == "hard":
  7. return 5
  8. else:
  9. return -1 #Error in the input.
  10.  
  11. difficulty = raw_input( "Choose your difficulty level - easy, medium, hard >> " )
  12. guessesLeft = getDifficultyLevel( difficulty )
  13.  
  14. #and for the main loop you could have
  15. while guessesLeft > 0:
  16. #Play the game here...
  17.  
  18. #outside the loop check if the user guessed the word. You could have a boolean variable 'win' or something and if the user guesses the whole word set 'win' to True...

you haven't read the words from a text file yet. Try to do that first in order to have something to work with hope this gives you some ideas
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC