I am trying to do a while loop that execute a function while the verification is not changed. my code looks like this:
from time import sleep
verif = 0
num = 5
def doso(num, verif):
if num%11 == 0:
verif += 1
elif num%14 == 0:
verif += 1
print(num)
return verif
while verif == 0:
doso(num, verif)
num += 1
sleep(1)
so for now it run infinitely... i would like if it stoped when it find a multiple of 11 or 14
**its an example
Arco Bast
3,9502 gold badges31 silver badges56 bronze badges
2 Answers 2
Try updating the variable:
while verif == 0:
verif = doso(num, verif)
num += 1
sleep(1)
answered Mar 17, 2020 at 16:15
Arco Bast
3,9502 gold badges31 silver badges56 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
To avoid running into an XY problem, note that you do not need verif at all. You can simply do:
num = 5
while True:
if num%11 == 0 or num%14 == 0:
break
else:
num += 1
answered Mar 17, 2020 at 16:20
Ma0
15.2k4 gold badges38 silver badges70 bronze badges
Comments
lang-py
verifis not changed inside the loop. You probably meant to doverif = doso(num, verif)verif += 1inside thedosofunction creates a local variable, but does not change the global variable defined above.