Goals

In this project, you will calculate the day of the week (Monday-Sunday) from a date provided by the user.

You will be practicing the following concepts from prior labs:


Summary

Zeller's congruence is a formula for determining the day of the week for a specific date. The inputs to the formula are:

Note:For a date that falls in January or February, you should use the previous year instead of the current year. So, if you are interested in finding the day on January 21, 2012, the formula would require q = 21, m = 13, K = 11 and J = 20.

Once you have the inputs, calculate a value h using the formula below:
Zeller's formula

In this formula, the square brackets around an expression represent the floor of that quantity. In Python, you can get the floor by using integer division (//) for all of these division operations. Also, "mod" refers to the remainder operator (%) in Python.

Once you have computed h using this formula, you can translate it to the day of the week as follows:
d = ((h + 5) mod 7) + 1
If d is 1, the day is Monday. A d of 2 means Tuesday, etc.


In this project, you will write a program that prompts the user for several dates (day, month and year), calculates the day for each date, and then reports some summary statistics about these days. This program will be built in stages: Checkpoint A, Checkpoint B, and then Final Code. There is a demo associated with each intermediate stage.

Part of this project is an exercise in having control over functions and patterns to produce target outputs. It is not a creative exercise, but rather the opportunity for you to demonstrate precision, control and being detail-oriented. You are asked to demonstrate the requested behavior and output, matching the sample output exactly. In all samples below, user input is shown in italics and underlined.

Due Dates


Checkpoint A

For Checkpoint A, you will need to demonstrate a program that does the following:

  1. Prompts the user to enter a specific date. You can assume that the user types valid dates after 1750 and understands the confusing rule about January and February.
  2. Prints the value of d after calculating it using the formula described in the Summary section.
  3. Matches the sample input/output below.

    We will use additional sample inputs to test your demo and your final program, and so should you. You can test your program using the Weekday calculator to check answers;

  4. Demo. Demo Checkpoint A.

Sample Input/Output

Sample 1
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

What day of the month is it (1-31)? 12
	-> You have selected q = 12
What month is it (3-14)? 5
	-> You have selected m = 5
What are the last 2 digits of the year? 18
What are the first 2 digits of the year? 20
	-> You have selected K = 18 and J = 20
	
The day of the week is 6.
Sample 2
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

What day of the month is it (1-31)? 28
	-> You have selected q = 28
What month is it (3-14)? 13
	-> You have selected m = 13
What are the last 2 digits of the year? 78
What are the first 2 digits of the year? 18
	-> You have selected K = 78 and J = 18
	
The day of the week is 2.

Checkpoint B

For Checkpoint B, you will extend your code from Checkpoint A to do the following:

  1. Prompt the user to enter the actual month (as opposed to entering 13 for January and 14 for February) and enter the complete year (as opposed to entering the last 2 and first 2 digits separately). Your program will need to compute the correct values for the variables q, m, K and J that are used in the formula. For example, for date 21 January 2012, q=21, m=13, K=11 and J=20.
  2. Print out the actual day of the week (Monday, Tuesday, etc.) instead of the numeric value of d.
  3. Match the sample input/output below exactly.

  4. Demo. Demo Checkpoint B.

Sample Input/Output

Sample 3
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

What day of the month is it (1-31)? 15
	-> You have selected q = 15
What month is it (1-12)? 2
	-> You have selected m = 14
What year is it? 2018
	-> You have selected K = 17 and J = 20

The day on 2/15/2018 is Thursday.
Sample 4
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

What day of the month is it (1-31)? 1
	-> You have selected q = 1
What month is it (1-12)? 1
	-> You have selected m = 13
What year is it? 2000
	-> You have selected K = 99 and J = 19

The day on 1/1/2000 is Saturday.
Sample 5
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

What day of the month is it (1-31)? 4
	-> You have selected q = 4
What month is it (1-12)? 7
	-> You have selected m = 7
What year is it? 3000
	-> You have selected K = 0 and J = 30

The day on 7/4/3000 is Friday.

Final Code

In your final code, you will extend the above code to handle multiple dates:

There is no demo for your final code.

Advice and Hints

Hint: float('inf') is larger than every other float, and float('-inf') is smaller than every other float. You may find these useful as variable initializers, when you are tracking minima and maxima.

Hint: The exit() function in the sys library can be used to halt the program running and report an exit code back to the operating system. Please use exit(-1), which will report it as an error. Here is a little code demonstrating this, but note that it will not run in PythonTutor (which does not let you use the sys library). You will need to copy-paste the code and run it in a different environment.

Sample Input/Output

Sample 6
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

How many dates do you want to compute? -3
Error: -3 is not a valid input
Sample 7
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

How many dates do you want to compute? 5

What day of the month is it (1-31)? 09
What month is it (1-12)? 11
What year is it? 2109

The day on 11/9/2109 is Saturday.

What day of the month is it (1-31)? 22
What month is it (1-12)? 2
What year is it? 1857

The day on 2/22/1857 is Sunday.

What day of the month is it (1-31)? 2
What month is it (1-12)? 10
What year is it? 1777

The day on 10/2/1777 is Thursday.

What day of the month is it (1-31)? 1
What month is it (1-12)? 1
What year is it? 1900

The day on 1/1/1900 is Monday.

What day of the month is it (1-31)? 31
What month is it (1-12)? 12
What year is it? 2018

The day on 12/31/2018 is Monday.

Summary Report
	Range of years provided are from 1777 - 2109
	Total number of weekdays are 3
	Total number of weekends are 2
Sample 8
=== Day from the Date Calculator ===
This program computes the day of the week that a date falls on.

How many dates do you want to compute? 3

What day of the month is it (1-31)? 14
What month is it (1-12)? 2
What year is it? 2018

The day on 2/14/2018 is Wednesday.

What day of the month is it (1-31)? 4
What month is it (1-12)? 7
What year is it? 2018

The day on 7/4/2018 is Wednesday.

What day of the month is it (1-31)? 15
What month is it (1-12)? 1
What year is it? 2018

The day on 1/15/2018 is Monday.

Summary Report
	Range of years provided are from 2018 - 2018
	Total number of weekdays are 3
	Total number of weekends are 0

Extra Credit

You can get extra credit by checking for more error conditions. For example, check any of the user's inputs for validity and exit the program or print an error message if they are invalid. More specifically, you could reject a negative number for the month. To get even fancier, you could reject a date of 30 in February, but not in March. You will get max +1 points for each boundary condition you check.

You can get extra credit by giving range of dates (as opposed to range of years) in the summary report (+5).

You will get no more than 10 points total for extra credit. Be sure you describe any extra-credit work in your docstring, explaining the judgements you made and you must include references justifying these judgements. If you do not describe your extra credit work, it will get ignored.


Grading Rubric

Checkpoints [20%]

Checkpoint demos are each worth 10 points; each is all or nothing.

Programming Design and Style [25%]

In addition to being correct, your program should be easy to understand and well documented. For details, see the rubric below.

Correctness [55%]

The most important part of your grade is the correctness of your final program. Your program will be tested numerous times, using different inputs, to be sure that it meets the specification. You will not get full credit for this unless your output matches the sample output exactly for every case, including capitalization and spacing. Attention to detail will pay off on this assignment. For details, see the rubric below.

Detailed Rubric

Correctness: functional features (50 points -- 5 points each)

Feature 1: For each date in January, a correct day is reported (Ex: Samples 4, 7 and 8).
Feature 2: For each date in February, a correct day is reported (Ex: Samples 3, 7 and 8).
Feature 3: For each year that is a beginning of a century, a correct day is reported (Ex: Samples 4, 5 and 7).
Feature 4: For each date that is in January or February and a year that is a beginning of a century, a correct day is reported (Ex: Samples 4 and 7).
Feature 5: For dates not included in Features 1 - 2, a correct day is reported.
Feature 6: For dates not included in Features 3 - 4, a correct day is reported.
Feature 7: When the user inputs an invalid number for the number of dates, the program produces an appropriate error message and exit code (Ex: Samples 5 and 6).
Feature 8: The minimum value in the range of years is correctly reported in the Summary Report (Ex: Samples 7 and 8).
Feature 9: The maximum value in the range of years is correctly reported in the Summary Report (Ex: Samples 7 and 8).
Feature 10: The number of weekdays and weekends is correctly reported in the Summary Report (Ex: Samples 7 and 8).

Correctness: spacing, spelling, grammar, punctuation (5 points)

Your spelling, punctuation, etc. get a separate score: each minor error in spacing, punctuation, or spelling gets a score of 2.5, and each major error gets a score of 5. Here is how the score translates to points on the assignment:

[5]Score = 0
-1 0 < Score <= 2.5
-2 2.5 < Score <= 5
-3 5 < Score <= 7.5
-4 7.5 < Score <= 10
-5Score > 10

Programming Design and Style (25 points)

Docstring (5 points)
There should be a docstring at the top of your submitted file with the following information:
1 pt.Your name (first and last)
1 pt.The course (CS 115)
1 pt.The assignment (e.g., Project 1)
2 pts.A brief description of what the program does
Documentation (6 points)
Not counting the docstring, your program should contain at least three comments explaining aspects of your code that are potentially tricky for a person reading it to understand. You should assume that the person understands what Python syntax means but may not understand why you are doing what you are doing.
6 pts.You have at least 3 useful comments (2 points each)
Variables (5 points)
5 pts.Variables have helpful names that indicate what kind of information they contain.
Algorithm (4 points)
2 pts.Your algorithm is straightforward and easy to follow.
2 pts.Your algorithm is reasonably efficient, with no wasted computation or unused variables.
Program structure (5 points)
All or nothing: your code should define a main function and then call that function, just like our programs do in the lab. Other than library imports, the docstring, and the final call to main(), you should not have any stray code outside a function definition.
Catchall
For students using language features that were not covered in class, up to 5 points may be taken off if the principles of programming style are not adhered to when using these features. If you have any questions about what this means, then ask.

Submission

You should submit your final code on Moodle by the deadline. I strongly encourage you to take precautions to make and manage backups while you work on your project, in case something goes wrong either while working or with your submission to Moodle.

Name the file you submit to Moodle yourlastnameP1.py, substituting your actual last name (in lowercase) for yourlastname.

Late Policies

Project late policies are outlined in the course policies page.

Collaboration Policy

Programming projects must be your own work, and academic misconduct is taken very seriously. You may discuss ideas and approaches with other students and the course staff, but you should work out all details and write up all solutions on your own. The following actions will be penalized as academic dishonesty:

Project collaboration policies are described in the course policies page.