CSCI 150 - Project 1
This Day in History
Overview
Many systems have been devised over the years for keeping time. In this project, you will
explore some of the oddities present in our current calendar system by using a formula
to calculate the day of the week for any given day between 1700 and 2299.
In particular, this project will cover the following concepts we have discussed in class:
- Input / Output
- Math module
- Standard functions (min, max, etc.)
- Conditionals
Description
Over the centuries, our calendar has been realigned many times to coincide with growth in
our astronomical knowledge. Incorporating elements of both the solar and lunar cycle, the
current international standard calendar is the
Gregorian Calendar, first
adopted in 1582. There are
seven days a week due to religious influence, 12 months to a year in honor of
the lunar cycle, and 365 days a year in relation to the earth's orbital period
around the sun, with enough
leap days included to properly align the system with the true
orbital period of approximately 365.242190419 days.
While better than the Egyptian and Roman calendars in use at the time of adoption, it is still
an approximation with room for improvement, from the more-precise
Iranian Calendar to
a standardized and perpetual
World Calendar.
One of the more interesting quirks of the Gregorian Calendar is that
each year can start on a different day of the week, since 365 is not
a multiple of 7. But there is a simple algorithm (based on the
Doomsday Rule) that
you can memorize to find the day of the
week for any date between
Jan 1st, 1700 and Dec 31st, 2299:
- Find the last 2 digits of the year. Divide this by four (using integer division)
and sum these two together to get
y
.
- Get the corresponding offset (shown below) for the month for
m
.
- Take the day to get
d
- Add
y
, m
and d
together to find dow
.
- Add the year offset (also shown below) to
dow
.
- If the year is a leap year and the month is January or February, subtract 1 from
dow
.
dow
mod 7 corresponds to the day of the week. (0 = Sunday,
1 = Monday, 2 = Tuesday, etc.)
Table for Month Offset
Jan | Feb | Mar | Apr | May | Jun |
Jul | Aug | Sep | Oct | Nov | Dec |
6 | 2 | 2 | 5 | 0 | 3 |
5 | 1 | 4 | 6 | 2 | 4 |
Table for Year Offset
1700 | 1800 | 1900 | 2000 | 2100 | 2200 |
5 | 3 | 1 | 0 | -2 | -4 |
For example, if you wish to know the day of the week for September 26th, 2014, these
are the steps you would take:
- 14 + 3 = 17
- 4
- 26
- 17 + 4 + 26 = 47
- 47 + 0 = 47 (offset code = 0)
- 47 - 0 = 47 (a leap year, but not Jan or Feb)
- 47 % 7 = 5 for Friday
Leap Year Rule
Under the Gregorian Calendar, a year is a leap year (such that February has 29 days) if it is a
multiple of four, except when it is also a multiple of 100 but not 400. So, 1900 and
2100 are not leap years, but 2000 is a leap year.
Coding
For this assignment, you will write a Python program called whatdayisit.py
.
This program will first tell the user about the program, and then take as input from the user
the date they wish to use for finding the day of the week. This input must be in the
form of one question to the user, formatted to have the day, then month, then year,
with each separated by a dash. The month and the day must both be two digit
entries, pad the beginning with 0 if necessary. So the user would type in "26-09-2014" for
September 26th, 2014.
With correct input, your program will then parse this input into the day, month and year,
follow the above algorithm to compute the day of the week, and output this to the user
in the following format (using September 26th, 2014 as an example):
The 26th of September, 2014 takes place on a Friday.
For dates, use st, nd, rd and th suffixes appropriately.
Testing
Test your code on the following dates to ensure you are getting the right answers. I will be
using other dates to test your project for grading, so you should also find three other dates than
these for your own testing, one of which is in January or February of a leap year.
- A total solar eclipse will occur over the continental United States on
Monday, August 21, 2017.
- The Arecibo message
was beamed into space on Saturday, 16 November 1974.
- Groundhog Day, Sunday, February 2, 1992.
- The
Mesoamerican Long Count calendar used by the Mayans begins a new cycle on
Friday, December 21, 2012. Some people thought this would be the end of the world.
- Your birthday.
Restrictions
You may not use lists or strings to store the offset data. This should be accomplished
with conditionals.
What to Hand In
Log in to Moodle.
Copy your whatdayisit.py
project into the directory called
project1
. Make sure
you have followed the Python Style Guide, and
have run your project through the Automated Style Checker.
You must hand in:
© Mark Goadrich, Hendrix College