jeudi 5 novembre 2020

Varialble re-initalized in multiple function calls

I have to execute the following code wherein I will be calling the function main again and again. so here as I need to use i = i+1, I need to declare and initialize i in the first place right, but when i call the main function it again defines i=0 and the whole purpose of i = i+1 is lost. How can I solve this error? I have given the condition just as an example. Basically what I want is i should be initialized only once, inspite of how many number of times main is called.

def main():
    i = 0
    if 0<1:
        i = i+1
        y = i

Aucun commentaire:

Enregistrer un commentaire