Pick item from dictionary depending on it's range

Basically I want to make a dictionary that would have a key like 7am - 10am and then based on the current time get the corresponding value from this dictionary.
For example:

  • 24am - 8am = 1
  • 8am - 8pm = 2
  • 8pm to 24am = 3

And if the current time is 1:15am it would return 1, if it was 9:36pm it would return 3 and if 8:01am it would return 2.
This probably isn’t the best explanation but I really don’t know how to do it better.

Instead of dictionary, use if then else block. It is too simple…

Greater than 0 and less than 8
Else (if Greater than equal to 8 and leads than equal to 20,

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.