Home > other >  Conditions in multiple functions (python)
Conditions in multiple functions (python)

Time:11-09

I have this code, but why when the time reach 0:30 nothing happens, where is my error?:

import datetime

def a():

   timing = [0, 30] #hours, #minutes
   while True:
       now = datetime.datetime.now()
       datas = [now.hour, now.minute]    
       if datas == timing:
            a.x = 5
        
def b():
    a()
    if "he" == "he":
        print(2)
    
         if a.x == 5:
             print("VER")
    
b()        

CodePudding user response:

I believe because you don't leave the while loop. You should add a break to if condition. It means if a.x is set, then program should leave the function a and get back to function b.

def a():

   timing = [18, 54] #hours, #minutes
   while True:
       now = datetime.datetime.now()
       datas = [now.hour, now.minute]    
       if datas == timing:
            a.x = 5
            break
        
def b():
    a()
    if "he" == "he":
        print(2)
    
        if a.x == 5:
            print("VER")
    
b()
  • Related