## Day of the Week for Any Date

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

### Day of the Week for Any Date

Code: Select all
`# Lists and Dictionaries. months = {'January': 6, 'February': 2, 'March': 2, 'April': 5, 'May': 0, 'June': 3, 'July': 5, 'August': 8, 'September': 4, 'October': 6, 'November': 2, 'December': 4}weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]# Fruitful Functions for Algorithm.def yearcode(y):    """Year Code Generator Algorithm"""    y = y % 100    y = y + (y / 4) % 7    return int(round(y))def monthcode(m):    """Retrieve Month Number from Month Dictionary"""    return int(months[m])def daycode(d):    """Simplify Day Input for Efficiency"""    return d % 7# Inputs.dayin = int(input("What Day?"))monthin = input("What Month?")yearin = int(input("What Year?"))# Define Variables for Functions.yearout = yearcode(yearin)monthout = monthcode(monthin)dayout = daycode(dayin)# Final Add-Up and Output.result = int((dayout + monthout + yearout) % 7)print("That date is a", weekdays[result])`

The user puts in the date, and it gives the weekday with 100% accuracy. I know this is pointless, there being a calender module in Python. However I wanted to integrate the Domesday Algorithm into Python. This is written in Python 3.
Occupation GCSE Computing Student.
Languages Python 3, JavaScript, HTML, Batch.
python-forum.org is epic!

alext6453

Posts: 4
Joined: Tue Feb 19, 2013 12:57 pm
Location: Hertfordshire, England.

### Re: Day of the Week for Any Date

I am sorry to tell you that your code does not work properly.
I am born on a Sunday, but your program puts that date on a Saturday.
Dietrich

Posts: 2
Joined: Thu Mar 28, 2013 2:42 pm

### Re: Day of the Week for Any Date

I just tried "12", "december" and "December" for the month and it failed on all of them. (I don't care to jump into the code and fix it, in case you want it to be an exercise for yourself.)
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Day of the Week for Any Date

I guess it doesn't work for some people because it doesn't count leap years, I guess.
Btw, sorry for the late reply
luis.simao.af98

Posts: 18
Joined: Thu May 16, 2013 8:37 pm

### Re: Day of the Week for Any Date

Never heard of a "doomsday algorithm" before. Seems like a really-really sick one, but entertaining (thanks for the laugh!).

Check this out (an excerpt from here):
Now let's do the odd months—months 1, 3, 5, 7, 9, and 11, i.e. January, March, May, July, September, and November.
Skip January and March for a moment.
Consider the following mnemonic phrase:
I work 9-5 at the 7-11

LMFAO. And this is probably 5% of the "algorithm"'s description.

Not sure if the "algorithm" is brain-dead or the OP has coded it incorrectly (which would be really easy to do), or both.
But: how's that compared to one line of Python that does that:
Code: Select all
`print time.ctime(time.mktime( (y, m, d, 11,11,11, -1,-1,-1)  ) )`
ochichinyezaboombwa

Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

### Who is online

Users browsing this forum: No registered users and 1 guest