python的作业求大神解答

Q2: Simulate \Hangman" game played by two players. For those who have never played the game, the
rules are simple. One player thinks of a secret word, and the other tries to guess it, letter by letter.
To learn more about \hangman" game, check out this website: http://www.manythings.org/hmf/
For this question, you don't have to worry about creating user interface. Thus, our Hangman game
is not a \real" Hangman game, but the idea is similar.
Game play should look like this (The word/characters in bold face are user input):
Enter the secret word (all in lowercase): hello
===============================
Word so far: *****
Take guess number 1: e
Got it!
Word so far: *e***
Take guess number 2: s
Sorry.
Word so far:*e***
Take guess number 3: l
Got it!
Word so far: *ell*
Take guess number 4: h
Got it!
Word so far: hell*
Take guess number 5: o
Got it!
Congratulations. You correctly guessed the word: hello
Do you want to play one more time? y/n? y
Enter the secret word (all in lowercase): two
===============================
Word so far: ***
Take guess number 1: e
...

# -*- coding:utf-8 -*-
def Guess(word):
    print '==============================='
    print 'Word so far:%s'%('*'*len(word))    
    for i in range(len(word)):
        while True:
            j=raw_input('Take guess number %d:\n'%(i+1))
            if j==word[i]:
                print 'Got it!'
                print 'Word so far:%s'%(word[:i+1]+'*'*(len(word)-i-1))
                break
            else:
                print 'Sorry!'
                print 'Word so far:%s'%(word[:i]+'*'*(len(word)-i))
while True:
    word=raw_input('Enter the secret word (all in lowercase):\n')
    Guess(word)
    print 'Congratulations. You correctly guessed the word: %s'%word
    choise =raw_input('Do you want to play one more time? y/n? \n')
    if choise=='n':
        print 'Exit Now...'
        break

>>>

Enter the secret word (all in lowercase):

hello

===============================

Word so far:*****

Take guess number 1:

a

Sorry!

Word so far:*****

Take guess number 1:

h

Got it!

Word so far:h****

Take guess number 2:

e

Got it!

Word so far:he***

Take guess number 3:

a

Sorry!

Word so far:he***

Take guess number 3:

l

Got it!

Word so far:hel**

Take guess number 4:

l

Got it!

Word so far:hell*

Take guess number 5:

a

Sorry!

Word so far:hell*

Take guess number 5:

o

Got it!

Word so far:hello

Congratulations. You correctly guessed the word: hello

Do you want to play one more time? y/n? 

n

Exit Now...

温馨提示:内容为网友见解,仅供参考
无其他回答

请大神们帮忙解答一下Python作业难题?
我的 请大神们帮忙解答一下Python作业难题? 用Python编写一个组合两个字符串的方法,从第一个字符串中提取一个字符,然后从第二个字符串中提取一个字符,依此类推。一旦一个字符串没有剩下的字符,它应该和另一个字符串一起继续... 用Python编写一个组合两个字符串的方法,从第一个字符串中提取一个字符,然后从...

python简单题不会,求解答
第一题:from __future__ import divisionprint '请依次输入体重(kg)与身高(m):'weight = float(raw_input())height = float(raw_input())print "{:.2f}".format(weight\/(height**2))#第二题:print '请输入一个秒数:'sec = int(raw_input())print str(sec\/3600)+' '+str(sec%3...

Python作业求助
txt = open("绝代风华.txt","r+",encoding='utf-8').read()#修改访问模式为"r+"txt2=txt.replace(",",' ').replace("。",' ')#还有什么符号就自己加吧txt3=open("E:\/\/绝代风华2.txt","w+",encoding='utf-8')#设置路径比较好,在文件名前加txt3.write(txt2)#写入替换好的文...

python编程基础课后题答案(python编程入门课后作业答案)
Python编程循环题总共五道题有没有大佬解答下麻烦了?拿这个每题的大概意思去百度加上Python基本都有答案的,如果请我吃两碗面粉这个是可以解决的。python求答案以下是一段Python程序,用于统计字符串“ab2b3n5n2n67mm4n2”中字符n出现的次数:```python string="ab2b3n5n2n67mm4n2"count=0 forcharins...

Python课程的期末大作业,设计五子棋游戏程序,界面报告都有
Python 大作业——五子棋游戏 姓名: 学号:5140829032 姓名: 学号:5140829008 一 游戏介绍:设计的五子棋游戏支持两人对下,黑方用左键单击,白方用右键单击,落子无悔,程序自行判断输赢,弹出结果对话框。游戏规则:双方需遵守不在空地点击,一次下一子。二 游戏代码设计:代码原创,无借鉴和抄袭。界面...

python 入门求解! 小白一个,是coursera上的python入门的最后一份作业...
list[0]elif smallest > i:smallest = i print "Minimum is", smallest 另外有两个小建议:最好不要把list作为变量名,因为list在python里是预先定义好的,这样写会覆盖原来的定义。可以把找最大最小值的代码写进一个function里面,然后最后调用一次印出结果。这样会整洁明了一些 希望对你有帮助。

求python大佬看看这两道题怎么做?
求python大佬看看这两道题怎么做? 已有如下集合:homework1={'作业1_41705560.eml','作业1_41706760.eml','作业1_41705661.eml','作业1_41701560.eml','作业1_41705791.eml'}homework2={'作业2_41708560.eml','作业2_4... 已有如下集合: homework1 = {'作业1_41705560.eml','作业1_41706760.eml','...

python回家作业:求1--200之间,有多少个连续的自然数之和等于555,把这 ...
一共6组,运行这段代码即可获得

怎么做一个python作业?
回答:用pandas创建一个dataframe,字段就是“学号”、“成绩分数”、“成绩等级” 你每录入一条数据,就往dataframe里写入一条,学号和分数是直接写进去的,等级就根据分数判断ABCDE后再写进去 查询的就是根据学号查就行了 如果把学号那个字段设为索引,查的就更快

求个大神辅导python turtle作业
turtle库,Turtle最早来自于LOGO语言,是专门用于小孩子学习编程的,一般科班出身或者有志在Python方向发展的都不会去学这个,直接跳过儿童教育。绘图主要有以下几个步骤:设置画板、设置画笔、控制海龟移动绘制图形、色彩填充。作业要自己写,编程就是实现“一步步达到目标”的过程,否则是失去了编程的意义。

相似回答