My code that searches for a word in a text file works only once before it keeps printing "Word is not found in word list." (I'm making a Python wordle game and I'm trying to check if the guess is in the word list that I have)
import random
count = 0
whichword = random.randint(0, 5756)
f = open("wordlist.txt","r")
file = open("wordlist.txt")
word = f.readlines()[whichword]
while count < 6:
guess = input("Guess a 5-letter word: ")
if len(guess) > 5:
print("There are more than 5 letters.")
elif len(guess) < 5:
print("There are less than 5 letters.")
elif(guess not in file.read()):
print("Word is not in word list.")
count += 1
Basically when I input a word that is in the wordlist, it'll not do anything the first time, but the second time I input a word, it'll output "Word is not in word list."
every single time even if the word is in the word list. Does anyone know how I can fix this?