from time import localtime #Create dictionary of activities activities = {8: 'Sleeping', 9: 'Commuting', 17: 'Working', 18: 'Commuting', 20: 'Eating', 22: 'Resting' } #Get the current time time_now = localtime() hour = time_now.tm_hour #Compare current hour with key fields in activities #If the current hour is less than the key, print that activity for activity_time in sorted(activities.keys()): if hour < activity_time: print (activities[activity_time]) break else: print ('Unknown, AFK or sleeping!')