This commit is contained in:
Andros Fenollosa 2016-11-27 10:23:07 +01:00
parent 2b7ba61912
commit 873a3301ca

View File

@ -64,9 +64,13 @@ def best_letter(word_resolve):
sorted_letters = sorted( sorted_letters = sorted(
letters.items(), key=operator.itemgetter(1), reverse=True letters.items(), key=operator.itemgetter(1), reverse=True
) )
# Best letter # Best letter
if len(sorted_letters) > 0:
return sorted_letters[0][0] return sorted_letters[0][0]
else:
end = True
print('No more possibilities')
return None
# End Functions # End Functions
@ -98,6 +102,7 @@ print('')
while play: while play:
# Get best letter # Get best letter
best_option = best_letter(word_resolve) best_option = best_letter(word_resolve)
if best_option:
# The guard not to give it back # The guard not to give it back
letters_used.append(best_option) letters_used.append(best_option)
print_words() print_words()
@ -122,10 +127,9 @@ while play:
word_resolve[int(pos) - 1] = best_option word_resolve[int(pos) - 1] = best_option
# Game over # Game over
end = True
for letter in word_resolve:
if letter != '_':
end = False end = False
if not '_' in word_resolve:
end = True
if end: if end:
play = False play = False
print('Game over :)') print('Game over :)')