Computer Science Question

What day of week will your birthday be on in 2021? What day of week was January 1, 2000? Rather than looking it up in a calendar, what if there were a program that could quickly give you the answer?

Problem Definition

Your job is to design, implement, debug, and test an interactive Python script to accept a date (in mm/dd/yyyy format) as input and display the day of the week. For example, if the user enters 3/17/2021, the output should be:

March 17, 2021 is a Wednesday.

There is a known algorithm to convert the month, day, year to the day of week. Your program will implement this algorithm:

a ß (14 – month) / 12

y ß year – a

m ß month + 12*a – 2

d ß (day + y + y/4 – y/100 + y/400 + (31*m)/12) % 7

where day, month, year are the values inputted by the user and a, y, and m are variables that hold the values needed to compute d which represents the day of week. The value assigned to d is guaranteed to be an integer in the range of 0 to 6, where 0 represents Sunday, 1 represents Monday, 2 represents Tuesday, etc.

You are free to design the output as desired, but it might look something like this:

Welcome to Date Matcher!

I know what day of the week any date any date falls on. Try me!

Please enter a date in the form mm/dd/yyyy: 1/11/2010

January 11, 2010 is a Monday.

Additional notes:

1. The day of week must be displayed along with the date as shown above. You should always use present tense (is) even for dates in the past.

2. Your program must implement the following programmer-defined functions:

a. dayOfWeek (month, day, year) which uses the provided algorithm to determine the day of week (0-6)

b. getMonthString(month) which returns the correct name of month; for example, if m is 1, this function returns “January”.

c. getDayString (d) which returns the correct name of day; for example, if d is 6, this function returns “Saturday”.

d. valiDate(month, day, year) which returns True if the date is valid and False otherwise.

3. The program must validate the user’s input. If the date inputted by the user is not valid, display that message and ask them if they want to enter another date. For the purposes of Project 2, a valid date must meet these conditions:

a. month is an integer between 1 and 12 (inclusively)

b. day is appropriate for the month, given this relationship:

i. January: 31

ii. February: 28

iii. March: 31

iv. April: 30

v. May: 31

vi. June: 30

vii. July: 31

viii. August: 31

ix. September: 30

x. October: 31

xi. November: 30

xii. December: 31

c. year is greater than 1582

4. Allow the user to enter as many dates as desired.

SAMPLE ASSIGNMENT
Powered by WordPress