CSC207 - Project 1
This Day in History

Assigned September 11 12 p.m.
Due September 21 1 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:

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:

  1. Find the last 2 digits of the year. Divide this by four (using integer division) and sum these two together to get y.
  2. Get the corresponding offset (shown below) for the month for m.
  3. Take the day to get d
  4. Add y, m and d together to find dow.
  5. Add the year offset (also shown below) to dow.
  6. If the year is a leap year and the month is January or February, subtract 1 from dow.
  7. dow mod 7 corresponds to the day of the week. (0 = Sunday, 1 = Monday, 2 = Tuesday, etc.)
Table for Month Offset

JanFebMarAprMayJun JulAugSepOctNovDec
622503 514624

Table for Year Offset

170018001900200021002200
5310-2-4

For example, if you wish to know the day of the week for September 21st, 2012, these are the steps you would take:
  1. 12 + 3 = 15
  2. 4
  3. 21
  4. 15 + 4 + 21 = 40
  5. 40 + 0 = 40 (offset code = 0)
  6. 40 - 0 = 40 (a leap year, but not Jan or Feb)
  7. 40 % 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 todayinhistory.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 three questions to the user, first asking for the year, then the month, then the day. These should be in the form of numbers. So the user would type in "2012", "9" and "21" for September 21st, 2012.

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 21st, 2012 as an example):

September 21st, 2012 is 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.

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 cs.centenary.edu through either Secure FTP or WinSCP using your cs login and password. Copy your todayinhistory.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, Centenary College of Louisiana