use goto in python

1

I have the following Script. For .py extention of python to do GOTO but I do not know if this works in Phyton v3.3.3

os.system('cls')
    if Resultados1 == 0:
        Resultados1 = 0
        goto .Nivel_1
    if Resultados2 == 0:
        Resultados2 = 0
        goto .Nivel_2
    if Resultados3 == 0:
        Resultados3 = 0
        goto .Nivel_3
    if Resultados4 == 0:
        Resultados4 = 0
        goto .Nivel_4
    if Resultados5 == 0:
        Resultados5 = 0
        goto .Nivel_5
    if Resultados6 == 0:
        Resultados6 = 0
        goto .Nivel_6
    if Resultados7 == 0:
        Resultados7 = 0
        goto .Nivel_7

        label .Nivel_1
        GeneralResultados = Resultados1
        Goto .end

        label .Nivel_2
        GeneralResultados = Resultados1+Resultados2/2
        Goto .end

        label .Nivel_3
        GeneralResultados = Resultados1+Resultados2+Resultados3/3
        Goto .end

        label .Nivel_4
        GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4/4
        Goto .end

        label .Nivel_5
        GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5/5
        Goto .end

        label .Nivel_6
        GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5+Resultados6/6
        Goto .end

        label .Nivel_7
        GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5+Resultados6+Resultados7/7
        Goto .end


        label .end
        print ('Tu resultado final es: ',GeneralResultados)

Tell me error Name Goto is not defined as it is? As little as it is a variable but I'm wanting to do as if goto was in Bat to go to a certain place when a function is fulfilled.

    
asked by Juan Carlos Villamizar Alvarez 26.07.2018 в 02:47
source

2 answers

2

Python does not have goto sentence, and for good reasons. It does not contribute to the readability of the code, but rather the opposite, and there is always another, more structured way to achieve the same.

Because of the syntax of your example code, it seems that you are using the module goto ( import goto ) that has never been thought to be used in reality, but rather it is a "joke" (published on April Fool's Day), and a proof that even in languages as readable as python, it is possible to make illegible things.

VictorR's response is part of this other response in StackOverflow , which is another joke, and another way to implement goto an even more coarse way.

In short, do not use goto .

Maybe if you explained what you want, we could give you an alternative way to implement it. What you have at the moment does not seem to make much sense, since you compare a variable with zero, and if it is zero, you assign zero to it (value that it already had anyway). [?]

At the moment, your code is equivalent to the following (which I do not find much sense either):

if Resultados1 == 0:
    GeneralResultados = Resultados1
elif Resultados2 == 0:
    GeneralResultados = Resultados1+Resultados2/2
elif Resultados3 == 0:
    GeneralResultados = Resultados1+Resultados2+Resultados3/3
elif Resultados4 == 0:
    GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4/4
elif Resultados5 == 0:
    GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5/5
elif Resultados6 == 0:
    GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5+Resultados6/6
elif Resultados7 == 0:
    GeneralResultados = Resultados1+Resultados2+Resultados3+Resultados4+Resultados5+Resultados6+Resultados7/7

print ('Tu resultado final es: ',GeneralResultados)
    
answered by 26.07.2018 / 10:00
source
0

goto It is not part of the standard python library, however you can implement your own goto function although it is not recommended

def goto(line):
    global lineNumber  
    line = lineNumber

You can read a little more about the topic here

    
answered by 26.07.2018 в 02:55