Zeller’s Algorithm allows us to predict the day of the week a particular date fell upon (or will fall upon). In this case, I implemented it to find the day of the week you were born on. (For some reason it doesn’t work on dates greater than 2000, it’s out by one day).
Pointers welcome, especially on optimization.
What day of the week were you born on?
What day of the week were you born on?
Sprich mit mir!
- Lundis
- Distorter of Reality
- Posts: 543
- Joined: 22 Aug 2008, 16:00
- 15
- Location: Deadlock of Awesome
- Contact:
Re: What day of the week were you born on?
Some comments,
Code: Select all
if month>2:
A=month-2
#elif month==1 or 2: - You can't do it this way, python's warnings are non-existant as usual though /sigh
#the statement above checks whether month equals 1, if it doesn't it checks "if 2", which is defined as true (only 0 is false)
#what you want is the following:
#elif month==1 or month==2:
#but the entire line is actually not necessary at all, since you're checking whether month is 1 or 2 afterwards anyway
elif month==1:
A=11
elif month==2:
A=12
#You could also get the same result with one statement like this:
#elif month==1 or month==2:
# A += 10
else:
print "Invalid Input"
...
R=Z%7
#Instead of the exhaustive elif statements at the end you can put the days names in a list
days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
#and print it like this using R as index:
print fname, lname, "was born on a", days[R]
Re: What day of the week were you born on?
I understand the reason for the question, but I could not resist, I was born on a Friday in July in 1968.
Unfortunately, after reading this I realize that I am really old now. Bummer
Unfortunately, after reading this I realize that I am really old now. Bummer
- Pong18
- Cyber Mushroom
- Posts: 357
- Joined: 20 May 2009, 16:00
- 14
- Location: Manila, Philippines
- Contact:
Re: What day of the week were you born on?
LOL! hahahaha! what a nice comment hehehe made my day, man!lonewolf wrote:I understand the reason for the question, but I could not resist, I was born on a Friday in July in 1968.
Unfortunately, after reading this I realize that I am really old now. Bummer
Re: What day of the week were you born on?
Lundis, thanks for the analysis. I'd have definetely used a list instead had I known about them sooner
Sprich mit mir!