0

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

3
  • 3
    because the value of verif is not changed inside the loop. You probably meant to do verif = doso(num, verif) Commented Mar 17, 2020 at 16:14
  • verif += 1 inside the doso function creates a local variable, but does not change the global variable defined above. Commented Mar 17, 2020 at 16:15
  • Does this answer your question? Using global variables in a function Commented Mar 17, 2020 at 16:15

2 Answers 2

2

Try updating the variable:

while verif == 0:
    verif = doso(num, verif)
    num += 1
    sleep(1)
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.