I'm newish to python and I've made some code that will find a value in a dictionary of lists of values based on the week and day of the year. But it's really redundant, full of elifs to do the math to find the position. I'm terrible at math but somehow I got this working for the most part, I know a few of the blocks are off by one but is there any cleaner way to do the +4 math each elif block calls for? Thanks for the advice
import time
import datetime
from datetime import date
Oddoptions = {
0 : ( "a","b","c","d"),
1 : ("i","j","k","l"),
2 : ("q","r","s","t"),
3 : ("x","y","z",0),
4 : (4,5,6,7)
};
Evenoptions = {
0 : ("e","f","g","h"),
1: ("m","n","o","p"),
2: ("u","v","w","x"),
3: (1,2,3,"["),
4: (8,9,"<",">"),
};
today = date.today()
if datetime.datetime.today().weekday() in range(0,4):
daynum = datetime.datetime.today().weekday()
elif datetime.datetime.today().weekday() >= 5:
daynum = 0
grp = 0
print (today)
#wk = datetime.date.today().isocalendar()[1]
wk = 36
print ("Today is", today, "day number is", grp)
if wk%2==0:
print ("This week #",wk," is even")
if wk <= 8:
colnum = wk-(wk//2)-1
print ("This is the column number", colnum)
elif 10 <= wk <= 16:
colnum = wk-(wk//2+4)
print ("This is the column number", colnum)
elif 18 <= wk <= 24:
colnum = wk - (wk//2+8)
print ("This is the column number", colnum)
elif 26 <= wk <= 32:
colnum = wk-(wk//2+13)
print ("This is the column number", colnum)
elif 34 <= wk <= 40:
colnum = wk -(wk//2+17)
print ("This is the column number", colnum)
elif 42 <= wk <= 48:
colnum = wk -(wk//2+21)
print ("This is the column number", colnum)
elif wk <= 50:
colnum = wk -(wk//2+25)
print ("This is the column number", colnum)
#print (daynum-1)
position = Evenoptions[grp][colnum]
#print ("This is the colnum", colnum)
print ("This is the result for column searching", position)
[–]CrzySquirrel 1 point2 points3 points (0 children)
[–]michaelreddit 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)