# The Calendar Problem¶

#### Make sure you cut off the video at the 1:00 mark, just before the professor explains HOW he performs this calculation. We will intentionally not show the professor’s solution at any time during this lesson, since the students will reproduce their own algorithm themselves.¶

In [1]:
from IPython.display import YouTubeVideo

Out[1]:

</font>

## Determine what day of the week YOUR BIRTHDAY will fall on this year.¶

#### Now have the students read this code block, which is written in the Python programming language. They can either read this on their own computer or on the classroom projector. Notice how the shift numbers are identical to what is written above.¶

In [2]:
def calculate_day(month,day):

if month==1: shift=0
elif month==2: shift=3
elif month==3: shift=3
elif month==4: shift=6
elif month==5: shift=1
elif month==6: shift=4
elif month==7: shift=6
elif month==8: shift=2
elif month==9: shift=5
elif month==10: shift=0
elif month==11: shift=3
elif month==12: shift=5
else: return "ERROR"

mytotal = day + shift

remainder = mytotal % 7

if remainder==0: return "Monday"
elif remainder==1: return "Tuesday"
elif remainder==2: return "Wednesday"
elif remainder==3: return "Thursday"
elif remainder==4: return "Friday"
elif remainder==5: return "Saturday"
elif remainder==6: return "Sunday"
else: return "ERROR"


#### Now have students verify that this program works, by inputting their birth month and birth date, and comparing their calculated Day of Week to the answer below. To run the program, they just need to hit the "Run" button above.¶

In [3]:
calculate_day(6,15)

Out[3]:
'Saturday'

#### In a Math class, we recommend ignoring the Python code that enables this widget tool to work. On the other hand, it might be worthwhile to explore this code block with a Programming class, going through the code line by line.¶

In [4]:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

interact(calculate_day, month=widgets.IntSlider(min=1, max=12, step=1, value=6), day=widgets.IntSlider(min=1, max=31, step=1, value=15))

Out[4]:
<function __main__.calculate_day(month, day)>