以下是我的代码。当我运行它时,它会报告所有都已关闭但不应该关闭。无法弄清楚错误在哪里
import datetime
import time
import pytz
openingtime = ('09:00')
closingtime = ('21:00')
localtime = int(datetime.datetime.now().strftime("%H"))
localtime = ('US/Pacific')
easterntime = ('US/Eastern')
UKtime = ('Europe/London')
def checktime(localtime):
bresult = False
if localtime > openingtime and localtime < closingtime:
bresult = True
return bresult
if checktime(localtime) == True:
print 'The Local Office is Open Now.'
else:
print 'The Local Office is Closed Now.'
if checktime(easterntime) == True:
print 'The East Office is Open Now.'
else:
print 'The East Office is Closed Now.'
if checktime(UKtime) == True:
print 'The UK Office is Open Now.'
else:
print 'The UK Office is Closed Now.'
答案 0 :(得分:3)
请考虑以下几行:
localtime = int(datetime.datetime.now().strftime("%H"))
localtime = ('US/Pacific')
第一行将localtime变量设置为当前小时的整数。然后第二行覆盖该变量,而是使其引用字符串&#39; US / Pacific&#39;。传递到checktime
函数时,该字符串将始终比关闭时间(字符串&#39; 21:00&#39;)更大,因此checktime
将始终返回False。