I've decide to practice solving anagrams, something I'm very bad at. I got 1000 most common words of English language, filtered those under 5 letters and over 9 and then wrote a simple script:
import random
from random import randint
words = []
file = 'new_words.txt'
with open(file) as f:
for line in f:
words.append(line)
while True:
i = randint(0, (len(words)-1))
question_list = list(words[i])
random.shuffle(question_list)
print(f"{''.join(question_list)}")
print(f'Please solve the anagram. Type "exit" to quit of "next" to pass:\n')
answer = input()
if answer == 'exit':
break
elif answer == 'pass':
pass
elif answer == words[i]:
print('Correct!')
elif answer != words[i]:
print('Epic fail...\n\n')
Now for some reason the output of the line print(f"{''.join(question_list)}") is printed over 2 lines like so:
o
nzcieger
Which is an anagram for 'recognize'. It also prints random numbers on letters per line:
ly
erla
Sometimes the whole anagram is printed properly.
I can't figure out what's causing this.
Aucun commentaire:
Enregistrer un commentaire