Programming Project 4: Calendar Functions
Collaboration: Solo! Work on these three programs by yourself with help from section leaders.
Due: Monday 3-October by 9:00 pm
Turn in: Complete and turn in three files tDate.py, easterDate.py, and dayNumber.py to the ISTA 130 D2L drop box named Project 4: Calendar Functions
Grading: 100 points. For specific criteria see the Grading Criteria section at the end of this file.
Goals: This project gives you a chance to practice writing programs that have functions requiring decisions while using a few string functions and a list. You will also need to use decisions to check for valid inputs.
Program 1: Develop a Python program intDate.py so users can input a string representing a day of the week. The program must print the day upon which Thanksgiving falls. In the United States, Thanksgiving day is on the 4th Thursday of November. You are asked to write methodtDate(dayNovBegins).
The string argument to tDate will be the first weekday of November. For example, tDate('TU') is used to determine the Thanksgiving day for years when November begins on a Tuesday. In this case, tDate should return 24, the 4th Thursday in November 2011.
ArgumenttDatereturns
'MO' 25
'TU' 24
'WE' ____
'TH' ____
'FR' ____
'SA' ____
'SU' ____
First complete the test cases for 'WE' through 'SU'. The dialogs should look like this.
First day of Nov? mOndayThanksgiving Day: 25 /
First day of Nov? Tue
Thanksgiving Day: 24 / First day of Nov? S
Invalid day
Input Details
•Assume the input string for the day of the week always has at least two characters
•Allow case insensitive input
•Example input that work for Monday includes: Monday Mo mO MO Mon moXYZ
•Example invalid input: M T W F S No Minday huh
•Notify the user if the first two characters cannot be made to be one of the 7 valid inputs to function tDate: MO TU WE TH FR SA SU
Arrange your program to have these two functions and the if __name__ == '__main__': at the bottom if you want to run Ricks's tests before turn in.
# Given 'MO' 'TU', ... 'SU', return the day upon of Thanksgiving, 24 for example
deftDate(dayNovBegins):
# TODO: Complete this function
# Input the day of the week to print the Thanksgiving Date or report Invalid day
defmain():
# TODO: Complete this function
# Allows import of this program from the optional test module without running this program
if __name__ == '__main__':
main()
Program 2 Develop a Python program in easterDate.py that inputs a year and prints the date of Easter for that year. A formula for computing Easter in the years 1900 through 2099 inclusive is as follows, a = year % 19, b = year%4, c = year % 7, d = (19 * a + 24) % 30, e = (2 * b + 4 * c + 6 * d + 5) % 7. The date of Easter is March 22 + d + e, which could be in April. This formula works for every year except 1954, 1981, 2049, and 2076. In these four years the formula produces a date that is one week too late. Your function must also work for these four years.
You are asked to use your own new function easterDate(year). For example, easterDate(2011) returns the string '04/24/2011'. The dialogs should look like this:
Year? 201104/24/2011
/ Year? 2049
04/18/2049 / Year? 1972
04/02/1972 / Year? 1913
03/23/1913 / Year? 2100
Out of range
Input/Output Details
•Assume input of valid integers only
•Print 'Out of range' if the year is not in the range of 1900 through 2099 inclusive
•The output takes the form of 'mm/dd/yyyy/ with leading zeros are required for the month and year
Arrange your program to have these two functions and the if __name__ == '__main__': at the bottom if you want to run Ricks's tests before turn in.
# Return the date upon which Easter falls, '04/18/2011' for example
defeasterDate(year):
# TODO: Complete this function
# Input the year and report if it is out of range or print a correct Easter Date
defmain():
# TODO: Complete this function
# Allows import of this program from the optional test module without running this program
if __name__ == '__main__':
main()
Program 3 Develop a Python program in dayNumber.py that accepts a month/day/year and calculates the corresponding day number. The day number of a year can be computed in three steps using int arithmetic:
(a) dayNum = 31 * (month - 1) + day
(b)if the month is after February subtract (4 * month + 23) // 10 from dayNum
(c)if it is a leap year and after February 29, add 1 to dayNum
You are asked to create 3 new functions:
- validDate(date)returnsTrue if the string argument is a valid calendar date. The arguments always take the form of month, day, and year as positive integers separated by / as in 'mm/dd/yyyy'. Examples: '01/01/2001' '02/28/2011'. If the string argument does not express a proper date, return False. Examples: '01/32/2011' 13/13/2011' '02/29/2011'
- isLeapYear(year) returnsTrue if year represents a leap year like 2000, 20012, but not 2100 or 20013. isLeapYear(2012) returns true.
- dayNumber(date) return how many days a valid date is into the year. dayNumber('01/03/2011') returns 3, dayNumber('12/31/2011'), and dayNumber('12/31/2012') returns 366.
The dialogs should look like this:
Date? 01/01/2011Day of year: 1 / Date? 02/01/2011
Day of year: 32 / Date? 12/31/2011
Day of year: 365 /
Date? 13/31/2012
Invalid date
Input/Output Details
•Assume input has the form 'mm/dd/yyyy/' with leading zeros in the month and day if either is less than 10
•Notify the user if the date input does not represent a correct calendar date. Examples of invalid dates: '13/32/2011' '01/29/2011'
Arrange your program to have these four functions and the if __name__ == '__main__': at the bottom if you want to run Rick's tests before turn in.
# Return True if date is a valid calendar date as in '02/29/2012' or '12/31/1766'
defvalidDate(date):
# TODO: Complete this function
# Return True if year is a leap year like 2000, 20012, but not 2100 or 20013
defisLeapYear(year):
# TODO: Complete this function
# Return how many days a valid date is into the year. dayNumber('01/03/2011') returns 3.
defdayNumber(date):
# TODO: Complete this function
# Read in a string as a month day and year and report the day number or invalid input
defmain():
# TODO: Complete this function
# Allows import of this program from the optional test module without running this program
if __name__ == '__main__':
main()
Optional You may run tests on your three methods if you place CalendarTests.py in the same folder (all identifiers and file names must match those above). To avoid running your programs requiring user input, add this code to the bottom of your programs:
# Allows import of this program from the optional test module without running this program
if __name__ == '__main__':
main()
Grading Crtieria 100 points,Subject to Change!
___ / 60 The 40 assertions in CalendarTests.py pass for the five requested functions (1.5 pts each)
___ / 16 All module (3) and method names (5) match so there are no errors when we run our tests (2 pts each).
Suggestion: Run Rick's tests
___/ 24 Style and Design
___ / 6 You commented (documented) each program as requested (see below)
___/ 6 You used meaningful names for all identifiers in both programs (subjective)
___/ 6 Your dialogs match
___/ 6 You performed error checking of input when requested
# Developer: [Your name]
#
# SL: [Your SL's name here]
#
# File: [programName.py]
#
# Due: [Project Due Date and Time]
#
# Purpose: [A one or two setence description of what the program does.]
#