我正在尝试学习 python,我正在尝试一个刽子手游戏。但是当我尝试将用户的猜测与单词进行比较时,它不起作用。我错过了什么?
import sys
import codecs
import random
if __name__ == '__main__':
try:
wordlist = codecs.open("words.txt", "r")
except Exception as ex:
print (ex)
print ("\n**Could not open file!**\n")
sys.exit(0)
rand = int(random.random()*5 + 1)
i = 0
for word in wordlist:
i+=1
if i == rand:
print (word, end = '')
break
wordlist.close()
guess = input("Guess a letter: ")
print (guess) #for testing purposes
for letters in word:
if guess == letters:
print ("Yessssh")
#guessing part and user interface here