# 我需要实现二进制搜索算法，然后将输入的8个随机字母与文本文件（列表）进行比较

``````def PlayGame(guess_word):

print("Game Starts Now")
random_words = GetRandomLetters()
print( " Your Phrase: ", random_words)

secret_word = "hello"
tries = 3
while tries > 0:
guess_word = input("Guess a word: ")
if guess_word != secret_word:
tries -= 1
print("Sorry, word not found, you have", tries, "tries left")
if tries == 0:
print("Ran out of tries!")
break
else:
print("Congrats, you found the word !!!")
PlayGame()
break

def BinarySearch():
array = GetJugWords()
target = input("Enter a word: ")
first = 0
last = len(array) - 1

while first <= last:
mid = (first + last) // 2
midpoint = array[mid]
if midpoint > target:
last = mid - 1
elif midpoint < target:
first = first + 1
else:
return midpoint

def GetRandomLetters():
letters = string.ascii_lowercase
random_letters = ''.join(random.choice(letters) for i in range(8))
return random_letters

def GetJugWords():
words_list = []
with open('jug_words.txt') as file:
for line in file:
line = line.strip()
words_list.append(line)
return words_list

if __name__ == '__main__':
PlayGame()
``````