Hi, I'm in need of some help in using functions for the hangman game. The professor doesn't understand how difficult it is for a first time programmer and just doesn't explain new concepts thoroughly. The game that I'm trying to code looks like this:
Enter the secret word: LETTERS
------------------------------------------------------------
Word so far: _______
Misses: 0
What letter would you like to guess? E
Word so far: _E__E__
Misses: 0
.
.
.
.
Word so far: _ETTERS
Misses: 3
What letter would you like to guess? L
You guessed the secret correctly: LETTERS
So Here's what i have so far:
#stuff the first person sees
def get_secret(word):
"""Get the secret word/phrase"""
input = raw_input(word)
Words_so_far = "_ " * len(word)
Misses = 0
max_wrong = 5
#Stuff the second person sees
word = raw_input("Enter the secret word:")
display = len(word)
print display
print word
print "\n"*10
print "_ " * display
def do_turn(display,misses):
"""
Display the current status for the user and let them make a guess.
"""
These were the tips the Prof gave, and so I'm just wondering if someone can help me on what the next step is. I can honestly say that it took me 3 hours to type the code that I have shown you. I don't want to get accused for plagiarism of any sort, so I would like a step by step help as if I were going to ask my prof for help. I'm sorry if this post is super long but here's the tips that my prof gave:
Start by creating a function get_secret that asks the user for the secret word/phrase, clears the screen, and returns the secret string.
def get_secret():
"""
Get the secret word/phrase.
"""
In the main part of the program, call the get_secret function and store the result in secret. Create a string display that contains len(secret) underscores.
The string display will be what we show the user as they are guessing. The underscores will be replaced with letters as they are guessed.
Create a variable to count the number of incorrect guesses the user has made (“misses”) and initialize it appropriately. You will also need to keep track of the number of unguessed letters left in the secret: this (along with the count of the misses) will be used to decide when the game is over.
Create a function do_turn that takes two arguments: the display string, and the number of misses made so far. This function should do the part of the turn the user sees (display the part of the secret they have guessed, display the number of misses, and ask them to guess a letter).
def do_turn(display, misses):
"""
Display the current status for the user and let them make a guess.
"""
Don't worry about the error checking (exactly one letter). The function should return the letter the user enters.
Once we have both the secret word, and a guess, we need to be able to update the display string, and keep track of the number of letters discovered. Create a function new_display that takes three arguments: the secret, the display string, and the letter the user guessed.
Once it has these values, the function can calculate the new value for the display string (i.e. replace all of the underscores where the letter the user guessed is the letter). While it does this, it can count the replacements.
Both of those values (the new display string string, and the replacement count) should be returned. A Python function can return multiple values like this:
return newdisp, count
Then, you can call the function and capture both return values like this:
display, count = new_display(…)