CSC207 - Project 1
This Day in History
Assigned September 17th 2 p.m.
Due September 26th 2 p.m.
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.)
- Strings
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 17th, 2008, these
are the steps you would take:
- 8 + 2 = 10
- 4
- 17
- 10 + 4 + 17 = 31
- 31 + 0 = 31 (offset code = 0)
- 31 + 0 = 31 (leap year, but not Jan or Feb)
- 31 % 7 = 3 for Wednesday
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 date_finder.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 ask for year first,
followed by month, followed by day, where each is entered as an integer number.
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 17th, 2008 as an example):
Sep 17, 2008 will fall on Wed.
For the day of the week, use the standard three-letter abbreviation for that day, such
that Monday is "Mon",
Tuesday is "Tue", etc.
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 other dates than
these for your own testing.
- 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.
- The
Mesoamerican Long Count calendar used by the Mayans begins a new cycle on
Friday, December 21, 2012. Some people think this will be the end of the world.
- Your birthday.
Restrictions
For this project, you are not allowed to use if - then - else
blocks for making
decisions. Determining if a year is a leap year may be difficult this way, but is not impossible,
especially since your end result is know if you should subtract one from your calculation.
You also may not use lists to store data. You should use only Strings. This will be possible
if you make all of your stored information of equal width within each table.
What to Hand In
Log in to cs.centenary.edu
through either Secure FTP or WinSCP using your
cs login and password. Create a subdirectory from csc207
called project1
. Copy your date_finder.py
project into this directory. 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 2008, Centenary College of Louisiana