What day of the week were you born on?

Questions about programming languages and debugging
Post Reply
User avatar
JohnB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 191
Joined: 13 Mar 2009, 17:00
15
Contact:

What day of the week were you born on?

Post by JohnB »

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.
Sprich mit mir!

User avatar
Lundis
Distorter of Reality
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?

Post by Lundis »

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]

lonewolf
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 185
Joined: 02 Dec 2010, 19:03
13

Re: What day of the week were you born on?

Post by lonewolf »

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

User avatar
Pong18
Cyber Mushroom
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?

Post by Pong18 »

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
LOL! hahahaha! what a nice comment hehehe made my day, man!
Image

User avatar
JohnB
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 191
Joined: 13 Mar 2009, 17:00
15
Contact:

Re: What day of the week were you born on?

Post by JohnB »

Lundis, thanks for the analysis. I'd have definetely used a list instead had I known about them sooner :wink:
Sprich mit mir!

Post Reply