早教吧作业答案频道 -->英语-->
用Python编辑一个猜单词的程序,必须使用Function1.Thesecondplayerhas7guessesasthereare7piecestothehangmanfigure.Thepiecesareaddedtothefigureinthefollowingorder:rope,head,torso,leftarm,rightarm,leftleg,rightleg.
题目详情
用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
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
▼优质解答
答案和解析
这英语看的头大,发你一个之前写的猜字游戏
#coding=utf-8
'''
Created on 2014-11-03
@author: Neo
'''
def myFind(key, word):
flag = False
ret = []
for i in range(0, word.__len__()):
if key == word[i]:
flag = True
ret.append(i)
if flag:
return ret
else:
return flag
def setSecretWord():
word = raw_input("Enter the secret word(all in lowercase):")
ret = []
for i in range(0, word.__len__()):
ret.append(word[i])
return ret
def showWord(word):
show = ['*']*word.__len__()
i = 1
while True:
print "Word so far: %s" % ''.join(show)
key = raw_input("Take guess number %d:" % i)
flag = myFind(key, word)
if flag:
for k in range(0,flag.__len__()):
show[flag[k]] = key
print 'Got it.\r\n'
else:
print 'Sorry.\r\n'
i += 1
ret = myFind('*', ''.join(show))
if ret == False:
print "Congratulations. You correctly guessd the word: %s\r\n" % ''.join(word)
break
def main(again):
if again == 'y':
word = setSecretWord()
print "
Word so far:***
Take guess number 1:e
Sorry.
Word so far:***
Take guess number 2:
.
#coding=utf-8
'''
Created on 2014-11-03
@author: Neo
'''
def myFind(key, word):
flag = False
ret = []
for i in range(0, word.__len__()):
if key == word[i]:
flag = True
ret.append(i)
if flag:
return ret
else:
return flag
def setSecretWord():
word = raw_input("Enter the secret word(all in lowercase):")
ret = []
for i in range(0, word.__len__()):
ret.append(word[i])
return ret
def showWord(word):
show = ['*']*word.__len__()
i = 1
while True:
print "Word so far: %s" % ''.join(show)
key = raw_input("Take guess number %d:" % i)
flag = myFind(key, word)
if flag:
for k in range(0,flag.__len__()):
show[flag[k]] = key
print 'Got it.\r\n'
else:
print 'Sorry.\r\n'
i += 1
ret = myFind('*', ''.join(show))
if ret == False:
print "Congratulations. You correctly guessd the word: %s\r\n" % ''.join(word)
break
def main(again):
if again == 'y':
word = setSecretWord()
print "
Word so far:***
Take guess number 1:e
Sorry.
Word so far:***
Take guess number 2:
.
看了 用Python编辑一个猜单词...的网友还看了以下:
英语选择题无须过程27.TrytosingmoreEnglishsongs,youwillfindi 2020-03-31 …
设两个正数之和为定数M,求其积的最大值(须过程)谢谢我们老师没交过均值不等式--omg~这个公式是 2020-04-11 …
七年级的几道解方程应用题,必须方程哈!1.学校组织九年级名团员去参加植树.如果挖坑,一天每人能挖树 2020-05-13 …
引用别人的话:‘’公用剃须刀可以传染艾滋病?是的。共用剃须刀有感染艾滋病的危险,如果和你共用剃须刀 2020-05-13 …
果园里有苹果树和梨树500棵,其中苹果树是梨树的2倍少40棵,问:苹果树和梨树各有多必须方程,而且 2020-05-14 …
已知等腰直角三角形斜边为100,求两直角边的长,须过程 2020-06-19 …
求一道初一一元一次方程应用题!赏分!必须方程,说思路!运动场一圈长400米,甲每分钟350米,乙每 2020-06-26 …
直线y=x+b被曲线y^2=4x截得的玄长为8倍根号2,求b的值须过程麻烦详细点谢谢! 2020-07-02 …
如图回答(1)图中①过程表示,②过程表示,③④过程表示.(2)通过图中③④过程可以看出,细胞是组织 2020-07-22 …
几何高手进!直接填答案,无须过程!有追加分!1平行四边形ABCD中,角A等于50度,则角B=?角C= 2021-02-01 …