Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on a code that will take any date input in form DD MM YYYY and return what day of the week it
I am working on a code that will take any date input in form DD MM YYYY and return what day of the week it is. I laid out my thoughts but I am struggling to connect them, also ignore my date variable, it should be DD MM YYYY not month name. NO IF STATEMENTS, NO FOR STATEMENT! Use only lists, tuples, index, slice. Python coding, I decided to use Zeller's Method which is below
\# -*- coding: utf-8 -*- "\|" Created on Thu Jan 19 @authon \#Zeller's date= list(input('Enter Date with format DD month name YYYY ) ) \#months tuple, March is 1 month_name= ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] \#sunday is day_name= ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] #a=[1,(i,0,6,,,,,,,1,1] \#month adjustment to make March be 1 b=[1,1,,,,,,,,,,] \#day of the month \#k=a+day_name \#month number m=b+ month_name \#laast two digits of year, I know this would use divide by 100 and floor D= \#first two digits of year, I know would be the remainder of the year/100 C= F=k+[(13mk)/5]+D+(D/4)+(C/4)(mC) print('The day of the week is ', F) Okay now for a real challenge! Write a program that will print out the day of the week (Monday, Tuesday, etc.) given any date (month, day, year). Python has several modules that have functions that will do this for you, but here you'll replicate that for practice. Input the month, day and year into your program as numbers (i.e. 1-12 for the month, 1-31 for the day, etc. No validation is required). F=k+[(13m1)/5]+D+[D/4]+[C/4]2Cwhere k is the day of the month. m is the month number. D is the last two digits of the year. C is the first two digits of the year. Note: According to Zeller's rule the month is counted as follows: March is 1, April is 2.... January is 11 and February is 12. So the year starts from March and ends with February. So if the given date has month as January or February subtract 1 from the year. For example: For 1 st January 1998 subtract 1 from 1998 i.e. 19981=1997 and use 1997 for calculating D. Discard all the decimal values and then find the final value of F. After getting the value of F, divide it by 7. The value of F can be either positive or negative. If it is negative, let us suppose F=15. When we divide by 7 we have to find the greatest multiple of 7 less than 15, so the remainder will be positive (or zero). 21 is the greatest multiple of 7 less than 15, so the remainder is 6 since 21+6=15. Alternatively, we can say that 7 goes into 15 twice, making 14 and leaving a remainder of 1.If we add 7 since the remainder is negative i.e. 1+7 we again get 6 as remainder. After getting the remainder we can find the day of the week for the given date. Following are the values for the corresponding remainders: m=2D=83C=19 Putting the values in the formula, we get, F=1+[(1321)/5]+83+83/4+19/4219=1+[(261)/5]+83+20.75+4.7538=1+25+83+2+438(discardingthedecimalvalues)=13338=75 After calculating F divide it by 7 and get the remainder. 78/7=11 Quotient 5-Remainder Therefore, the day on 1st April 1983 was Friday since the remainder is 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started