Writing codes with python 3

0

I am currently working on a project, where in one of the functions the script has to write a certain code that was generated from parameters chosen by the user, however after having generated such a code and added the same code file, I noticed that there is always an error in the identation. To do the same work I have to go to the editor and re-tabulate all the lines, even if the tab is correct, I tried to change the editor and even use python itself, but the same error returns.

Follow the code to generate:

    def criarHabilidade(self, nome, classe, valorMinimoParaAcertar, danoMinimo, danoMaximo):
        habilidadesCriadas[nome] = classe

        habilidade = '''

def {0}(self, dado, alvo = "sem", estadoDoJogador = "normal"):
    dano = 0
    if estadoDoJogador == "normal":
        if dano >= {1}:
            dano = random.randint({2}, {3})
        else:
            dano = 0
            return "Errou"
        if alvo != "sem":
            resultado = alvo.levarDano(dano)
            if resultado == "Morreu":
                return alvo.nome+": Morre!"
            else:
                return alvo.nome+": -"+str(dano)+" vida. Vida atual: "+str(alvo.vida)
        else:
            return dano
    else:
        return "Impossivel atacar! Jogador morto ou sob efeito de algo..."

'''.format(nome, valorMinimoParaAcertar, danoMinimo, danoMaximo)

Follow the resulting code:

#Habilidades criadas 007689


def oi(self, dado, alvo = "sem", estadoDoJogador = "normal"):
    dano = 0
    if estadoDoJogador == "normal":
        if dano >= 1:
            dano = random.randint(1, 1)
        else:
            dano = 0
            return "Errou"
        if alvo != "sem":
            resultado = alvo.levarDano(dano)
            if resultado == "Morreu":
                return alvo.nome+": Morre!"
            else:
                return alvo.nome+": -"+str(dano)+" vida. Vida atual: "+str(alvo.vida)
        else:
            return dano
    else:
        return "Impossivel atacar! Jogador morto ou sob efeito de algo..."

asked by anonymous 27.01.2018 / 11:01

1 answer

0

Python has some problems with indentation and tabulation.

When I use text editors like atom (and similar) I always set up for python files to always use whitespace instead of tabbing. Use a fixed number of blanks in the tab place that your problem will be resolved.

    
27.01.2018 / 11:47