-1
对于我的hangman应用程序,代码如下所示;在Hangman-python3列表中找到重复字符
text=list(input("Enter the word to be guessed:"))
guess=[]
tries=5
clue=input("Enter a clue: ")
print('RULES:\n 1) type exit to exit applcation \n 2) type ? for the clue')
for i in range(len(text)):
t='_ '
guess.append(t)
print(guess)
while True:
g=input("Guess a letter: ")
if g in text:
print("you guessed correct")
y=text.index(g)
guess[y]=g
print(guess)
continue
elif g=='exit':
exit()
elif g=='?':
print(clue)
elif tries==0:
print ("you have run out of tries, bye bye")
exit()
else:
print(g,' is not in the word')
tries -=1
print("you have",tries,'tries left')
continue
为实例的代码,如果该文本被猜测是“阿凡达”,当“a”是猜到了,它会返回只有字母而不是职位初审;文本[2] [4]
由于某种原因,对我来说不会工作,代码是否会运行Python3.x? – reuben
你有什么错误? – Vince
y = [i.start()for i in re.finditer(g,text)] 文件“/Users/----/anaconda/lib/python3.5/re.py”,第220行,在finditer中 return _compile(pattern,flags).finditer(string) TypeError:期望的字符串或类似字节的对象 – reuben