Question

Write a simple Python program to find the day for the given date. The procedure to...

Write a simple Python program to find the day for the given date. The procedure to find the day of the week is as follows:   

F = (K + (13 * m – 1) mod 5 + D + D mod 4 + C mod 4 – 2 * C ) mod 7

where, K : day of the month

m : month number

D : remainder when year divided by 100

C : quotient when year is divided by 100

Note: month is counted as follows: March is 1

April is 2 ……

January is 11

February is 12

So, the year starts from March and ends in February. So, if you have a month as January or February, then subtract 1 from the year.

Example 1: if the entered date is 1st January 2000, then:

K = 1

m = 11

D = (2000 -1 ) mod 100 = 99

C = (2000 -1 ) quotient 100 = 19

F = (1 + (13 * 11 – 1) mod 5 + 99 + 99 mod 4 + 19 mod 4 – 2 * 19 ) mod 7

= 6

If the value of F is:
0 : Sunday

1 : Monday

2 : Tuesday

3 : Wednesday

4 : Thursday

5 : Friday

6 : Saturday

So, the data 1st January 2000 is Saturday.

Example 2: if the entered date is 1st April 1983, then:

K = 1

m = 2

D = 1983 mod 100 = 83

C = 1983 quotient 100 = 19

F = (1 + (13 * 2 – 1) mod 5 + 83 + 83 mod 4 + 19 mod 4 – 2 * 19 ) mod 7

= 5

So, the data 1st April 1983 is Friday.

Sample Test Data:

Please enter the date: 2nd March, 2004

Sample Output:

The day is Tuesday

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN PYTHON:

date = int(input("Enter a date:"))
month = input("Enter a month:")
year = int(input("Enter a year:"))


month = month.upper()

monthList = ["MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER", "JANUARY", "FEBRUARY"]
m = monthList.index(month) + 1

k = date
d = year % 100
c = year // 100
f = (k + (13 * m - 1) % 5 + d + d % 4 + c % 4 - 2 * c ) % 7

weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

dayString = weekDays[f-1]
print("The day is",dayString)

INDENTATION:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write a simple Python program to find the day for the given date. The procedure to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Worth 5 points (Science: day of the week) Zeller's congruence is an algorithm developed...

    in python Worth 5 points (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h= (q + 26(m+1)//10 + k + k//4 +j//4 +5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - is the day of the month. m is the month (3: March, 4: April, ...,...

  • USING PYTHON. (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller...

    USING PYTHON. (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + 26(m+1)//10 + k + k//4 +j//4 +5j) % 7 where - h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). - q is the day of the month. - m is the month (3: March, 4: April, ...,...

  • General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You sho...

    General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You should create identifiers with sensible names; • You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. • Logical structures and statements are properly used for specific purposes. Objectives This assignment requires you to write...

  • Coding in C++ Write a program using structures to store the following weather information: - Month...

    Coding in C++ Write a program using structures to store the following weather information: - Month name - Day of month (Monday, Tuesday, etc) - High Temperature - Low Temperature - Rainfall for the day Use an the input.txt file to load the data into weather structures. Once the data for all the days is entered, the program should calculate and display the: - Total rainfall for the data - Average daily temperatures. (note: you'll need to calculate the days...

  • Write a function to determine the day of the week a person was born given his...

    Write a function to determine the day of the week a person was born given his or her birthday. The following steps should be used to find the day of the week corresponding to any date from 1901 through the present. In the following explanation, the following terms will be helpful. Assuming I type in my birthday as "6 10 1981": The month is 6. The day of the month is 10. The year is 1981. Find the number of...

  • Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm...

    Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + (26 * (m + 1)) / 10 + k + k / 4 + j / 4 + 5 * j) % 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q...

  • SQL- Microsoft Access List the employee number, employee last name, and pilot license type (if an...

    SQL - Microsoft Access --------------------------------------------------------------------- SQL- Microsoft Access List the employee number, employee last name, and pilot license type (if any) for all employees. (Hint: LEFT oUTER JOIN or OUTER JOIN must be used, because "if any"-some of them are not pilots). EMP NUM EMP TITLE EMP LNAME EMP FNAME EMP INITIAL EMP DOB EMP HIRE_DATE Click to Add 100 Mr 101 Ms. 102 Mr 103 Ms. 104 Mr 105 Mr 106 Mrs 107 Mr 108 Mr 109 Ms. 110...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

  • IN PYTHON, Write a program that reads a string from the user containing a date in...

    IN PYTHON, Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']. Use the month number you got from "mm" to get the month name.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT