Few things that I think will help ya in the long run...
multi_line_string = """
Do you want to use the previous word?
Yes/No
"""
print(multi_line_string)
Multi-line strings maybe assigned via triple quote (either """ or ''') blocks; having the stray apostrophe becomes no big deal. Furthermore one can utilize dedent from textwrap while printing such that the flow isn't broken...
from textwrap import dedent
some_string = """
Sorry, you've used all available possibilities!
... taking a nap...
"""
print(dedent(some_string))
Functions/Methods (definitions) are super useful for repeated snippets of code...
from textwrap import dedent
from translate import Translator
to_lang = 'en'
translator = None
if to_lang != 'en':
translator = Translator(to_lang = to_lang)
def accessibility(msg, **kwargs):
"""
Side note, this is a `__doc__ string` that _documents_
how something is intended to be used. And is accessible
via commands such as;
print(accessibility.__doc__)
help(accessibility)
This is a shortcut for formatting and then translating
passed `msg` string prior to `return`ing.
"""
if kwargs:
msg = msg.format(**kwargs)
if translator:
msg = translator.translate(msg)
return msg
def whats_wanted(msg, **kwargs):
"""
Simple short-cut for getting user input while also
translating `msg` if necessary.
"""
return input(accessibility(msg, **kwargs))
## ... also do __not__ be afraid of blank lines, two between
## classes and functions, and one between blocks and/or
## where it makes since to do so is the _rule of thumb_
## that I use when writing. Also it's a good idea to
## avoid comment blocks of this length, keep things _tight_
## and use `__doc__ strings` to avoid feeling the need for'em ;-)
the_question = "Shall we continue {user}?"
an_answer = whats_wanted(the_question,
user = 'yourName here')
if translator:
reverse_translator = Translator(to_lang = 'en')
the_answer = reverse_translator.translate(an_answer)
else:
the_answer = an_answer
if the_answer.lower() == 'yes':
msg = accessibility("I think I heard a 'yes' from {user}",
user = 'yourName here')
else:
msg = accessibility('What are you talking about?')
print(msg)
The try blocks may need a little rewriting, following is a starting point...
## ... Other code trimmed...
if old == 0:
_msg = """
Sorry, you used all your possibility
Do you want to restart the game?
Yes/No
"""
print(textwrap.dedent(_msg))
choose = input('>: ').capitalize()
# from this point on, the user has the opportunity
# to restart the game with the previous word(if not
# guessed) or not, or close it
try: ## To do something that may result in an exception
SENTINEL = answers[choose]
except KeyError: ## that some errors will occur
msg = 'Please, insert a correct answer'
choice = 0
print(textwrap.dedent(msg))
else: ## Do things when there was no exceptions
msg = '''
Do you want to use the previous word?
Yes/No
'''
print(textwrap.dedent(msg))
choose = input('>: ').capitalize()
finally: ## Do things when there where no un-caught exceptions
if choose == 'Yes':
choice = int(lenght*(3/2))
choices.clear()
elif choose == 'No':
choice = -1
SENTINEL = 1
else:
choice = -1
SENTINEL = 0
## ... other stuff...
... which'll hopefully expose bugs a bit easier; some will remain hiding though because you've got some formatting issues elsewhere as @Josay already pointed out.
With a little debugging and some tasteful use of abstraction you'll get there, so keep at it and in a few months time your code wont be as much of a danger to sobriety.