vendredi 19 février 2021

Variable handling between class and functions

I am trying to run the script until a randomly generated number is not matching with the thread number. I am using multi-thread. (I just copied here one of them).

Everything did work well until I moved the randomnumbers() generator in a function. As long as the generated number was in the "runmain" function, it was fine.

def randomnumbers():
    guessednumber = random.randint(1,101)
    return guessednumber

def runmain(number, guessednumber):
    while guessednumber!= number:    
        randomnumbers()
        if guessednumber == number:
            print(guessednumber)
            print(number)

class myClass1(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
        self.start()
    def run(self):
        while True:
            number = 1
            randomnumbers()
            runmain(number, guessednumber)

myClass1()

What I am missing?




Aucun commentaire:

Enregistrer un commentaire