python练习,不能使用find函数,命令中至少构建3个函数,要求python2.7
1个回答
展开全部
没用到三个函数,但功能有了
def check(input_str, guess_char, secret):
length = len(input_str)
flag = False
for i in range(length):
if guess_char == input_str[i]:
secret[i] = input_str[i]
flag = True
return flag
def main():
while (True):
input_str = raw_input("Enter the secret word(all in lowercase): ")
print "======================================="
secret = ['*' for i in range(len(input_str))]
count = 0
while '*' in secret:
count += 1
print 'Word so far: ', ''.join(secret)
guess_char = raw_input("Take guess number " + str(count) + ": ")
if check(input_str, guess_char, secret):
print 'Got it! '
else:
print 'Sorry. '
print "Congratulations! You correctly guessed the word: ", input_str, "\n"
again = raw_input("Do you want to play one more time? y/n? ")
if again == "n":
break
else:
continue
if __name__ == "__main__":
main()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询