Trees Jin
Trees Jin

Reputation: 21

Conditions in multiple functions (python)

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()        

Upvotes: 0

Views: 63

Answers (1)

amir
amir

Reputation: 26

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()

Upvotes: 1

Related Questions