用Python编辑一个猜单词的程序,必须使用Function
用Python编辑一个猜单词的程序,必须使用Function
1.The second player has 7 guesses as there are 7 pieces to the hangman figure.The pieces are added to the figure in the following order:rope,head,torso,left arm,right arm,left leg,right leg.
2.At the beginning of the game the first player should be asked to enter the secret word.All characters are legal excluding and white space characters (tab,space,newline).After the user enters a word you should display 30 newlines so as to hide the secret word.
3.At the beginning of each round you should display in this order:The hanged man,the partially guessed secret word,the characters guessed so far.
4.For the secret word,the characters that have not been guessed should be displayed as
5.Guesses for the characters in the secret word should be case insensitive.Store the entered secret word in lowercase and convert all guessed characters to lower case.
6.Leading and trailing white space should be removed from the user's guess before checking it
7.The user must enter a guess.If they do not they should be told that they must enter a guess and receive the prompt to enter the next character again.This should continue until the user enters a new character.
8.If the user guesses a character that they have already guessed then they should be told that they already guessed that character and be given the opportunity to guess again.This should continue until the user enters a new character.These guesses should not be counted against the user.
9.The user can only guess 1 character at a time.If the user enters more than 1 character they should be told that they can only enter 1 character and be given the opportunity to guess again.This should continue until the user enters a new character.
10.The letters that have been guessed so far should be displayed in sorted order.
11.If the user guesses the secret word they should be told that they guessed the secret word.
12.If the user does not guess the secret word they should be told that they failed to guess the word and the word should be revealed.
13.You MUST USE FUNCTIONS for this program and you should approach this problem in a top down manner.Your program must have at least the following functions.The parameters your function accepts are up to you to decide.
1.get_secret_word
1.This function should get a valid secret word from the user and return it.
2.is_game_over
1.This function should return True if the game is over and false otherwise
3.display_hangman
1.This function should display the current hangman figure
4.display_guesses
1.This should display the guesses the user has made in alphabetical order
5.get_guess
1.This should get a valid guess from the user