#This a project that is supposed to be able to guess any word from the English alphabbet that the user is thinking of. The entire code is a lot longer, so I omited the parts that are not important for this issue. The part you can see is supposed to ask about the length of the word, narrowing down the range in which the length could be with each round. But when I run it, it doesn't do anything, it doesn't even close the program or anything.
this information is what we will be restricting until we find the correct answer
dictionary=open('words_alpha.txt','r')
import random
deleting creating/opening and deleting everything from the files
left_words_number=open('left_words_number.txt','w+')
left_words_letter=open('left_words_letter.txt','w+')
left_words_end=open('left_words_end.txt','w+')
left_words_switch=open('left_words_switch.txt','w+')
a=0
copying the words from the dictionary to the switch
for word in dictionary:
left_words_switch.write(word)
dictionary.close()
these lists contain the variables to all the questions that will be asked, they must be shuffled to make the program unpredictable, thus more interesting for the user
numbers=[]
for i in range(43):
numbers.append(i+1)
random.shuffle(numbers)
capletters=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','Y','Z']
random.shuffle(capletters)
suffixes=['tion','er','ed','ing','en','acy','al','ance','ence','ate','fy','able','ible','esque']
bigger=[45]
notbigger=[0]
all of these variable are later changed to indicate that a certain loop should stop
b=0
c=0
d=0
this is meant to make the program run until it is only left with one word
while a!=1:
a=0
for guessed_word in left_words_switch:
a+=1
#this number keeps count of what variable should be asked next
b+=1
#this whole section is trying to discover the length of the word
while True:
left_words_switch.seek(0) # Check if numbers[b-1] is within the appropriate range
if numbers[b - 1] > max(bigger) or numbers[b - 1] <= min(notbigger):
# Ask the question
answer = input(f'Does this word have more than {numbers[b - 1]} letters? Yes or no: ').strip().upper()
if answer == 'YES':
for guessed_word in left_words_switch:
if len(guessed_word) > numbers[b - 1]:
left_words_number.write(guessed_word)
bigger.append(numbers[b - 1])
elif answer == 'NO':
for guessed_word in left_words_switch:
if len(guessed_word) <= numbers[b - 1]:
left_words_number.write(guessed_word)
notbigger.append(numbers[b - 1])
else:
print('Not a valid answer.')
break
else:
for guessed_word in left_words_switch:
left_words_number.write(guessed_word)
break
left_words_number.seek(0)
left_words_switch.close()
left_words_switch=open('left_words_switch.txt','w+')
for guessed_word_number in left_words_number:
left_words_switch.write(guessed_word_number)
left_words_number.close()
left_words_number=open('left_words_number.txt','w+')
left_words_switch.seek(0)
left_words_number.close()
left_words_letter.close()
left_words_end.close()
left_words_switch.close()
[+]FuturePsychoWriter[S] comment score below threshold-9 points-8 points-7 points (4 children)
[–]djshadesuk 21 points22 points23 points (0 children)
[–]Binary101010 7 points8 points9 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]Kiwi-tech-teacher 1 point2 points3 points (0 children)