[Python] Can't make my "while" cycle remember variables [closed]

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    Looked through many answers to my problem, but nothing works.

    The problematic part of the code looks like this:

    var1=1
    var=0.5
    i=0
    while i<20:
    var1=var+5
    var=var1
    i+=1
    print("TEST var", var, "iteration", i)
    print("TEST var1", var1)


    It finishes 1st cycle and just wipes memory clean and both "var1" and "var" become "nun" and further calculations break. Like so:

    TEST var 5.5 iteration 0
    TEST var1 5.5
    TEST var nan iteration 1
    TEST var1 nan
    TEST var nan iteration 2
    TEST var1 nan
    TEST var nan iteration 3
    TEST var1 nan
    ...


    I tried making it a list, but it still forgets.

    I have experience coding, but still find dumb ways to get stuck on simple tasks... Need help :(

    Continue reading...

Compartilhe esta Página