字典翻译 问答 小学 英语 用Python编辑一个猜单词的程序,必须使用Function1.Thesecondplayerhas7guessesasthereare7piecestothehangmanfigure.Thepiecesareaddedtothefigureinthefollowingorder:rope,head,torso,leftarm,rightarm,leftleg,rightleg.
问题标题:
用Python编辑一个猜单词的程序,必须使用Function1.Thesecondplayerhas7guessesasthereare7piecestothehangmanfigure.Thepiecesareaddedtothefigureinthefollowingorder:rope,head,torso,leftarm,rightarm,leftleg,rightleg.
问题描述:

用Python编辑一个猜单词的程序,必须使用Function

1.Thesecondplayerhas7guessesasthereare7piecestothehangmanfigure.Thepiecesareaddedtothefigureinthefollowingorder:rope,head,torso,leftarm,rightarm,leftleg,rightleg.

2.Atthebeginningofthegamethefirstplayershouldbeaskedtoenterthesecretword.Allcharactersarelegalexcludingandwhitespacecharacters(tab,space,newline).Aftertheuserentersawordyoushoulddisplay30newlinessoastohidethesecretword.

3.Atthebeginningofeachroundyoushoulddisplayinthisorder:Thehangedman,thepartiallyguessedsecretword,thecharactersguessedsofar.

4.Forthesecretword,thecharactersthathavenotbeenguessedshouldbedisplayedas

5.Guessesforthecharactersinthesecretwordshouldbecaseinsensitive.Storetheenteredsecretwordinlowercaseandconvertallguessedcharacterstolowercase.

6.Leadingandtrailingwhitespaceshouldberemovedfromtheuser'sguessbeforecheckingit

7.Theusermustenteraguess.Iftheydonottheyshouldbetoldthattheymustenteraguessandreceivetheprompttoenterthenextcharacteragain.Thisshouldcontinueuntiltheuserentersanewcharacter.

8.Iftheuserguessesacharacterthattheyhavealreadyguessedthentheyshouldbetoldthattheyalreadyguessedthatcharacterandbegiventheopportunitytoguessagain.Thisshouldcontinueuntiltheuserentersanewcharacter.Theseguessesshouldnotbecountedagainsttheuser.

9.Theusercanonlyguess1characteratatime.Iftheuserentersmorethan1charactertheyshouldbetoldthattheycanonlyenter1characterandbegiventheopportunitytoguessagain.Thisshouldcontinueuntiltheuserentersanewcharacter.

10.Thelettersthathavebeenguessedsofarshouldbedisplayedinsortedorder.

11.Iftheuserguessesthesecretwordtheyshouldbetoldthattheyguessedthesecretword.

12.Iftheuserdoesnotguessthesecretwordtheyshouldbetoldthattheyfailedtoguessthewordandthewordshouldberevealed.

13.YouMUSTUSEFUNCTIONSforthisprogramandyoushouldapproachthisprobleminatopdownmanner.Yourprogrammusthaveatleastthefollowingfunctions.Theparametersyourfunctionaccepts

钱瑞伟回答:
  这英语看的头大,发你一个之前写的猜字游戏   #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.rn'   else:   print 'Sorry.rn'   i += 1   ret = myFind('*', ''.join(show))   if ret == False:   print "Congratulations. You correctly guessd the word: %srn" % ''.join(word)   break   def main(again):   if again == 'y':   word = setSecretWord()   print "   Wordsofar:***   Takeguessnumber1:e   Sorry.   Wordsofar:***   Takeguessnumber2:   .
点击显示
英语推荐
热门英语推荐
  • 语文
  • 数学
  • 英语
  • 科学
  • 作文