This is probably very simple, but I am a beginner in python and I wanted to compare birthday dates by prompting a user to enter a date in MM-DD format. No year because year is current year (2011). It will then prompt the user to enter another date, and then the program compares it to see which one is first. Then it prints out the earlier day and it's weekday name.

Example: 02-10 is earlier than 03-11.
02-10 is on thursday and 03-11 is on friday

I just started learned modules and I know i'm supposed to use the datetime module, a date class and strftime to get the weekday name. I don't really know how to put it all together.

If someone can help me get started that would really help! I have some bits and pieces together:

You have some problems with indentations, that's obvious. And why did you use try only once? You read two dates. I don't really understand your moves. You should first read a good Python-language tutorial. docs.python.org/tutorial/index.html
–
Maciej ZiarkoMar 13 '11 at 8:54

3 Answers
3

There are a few problems I can see in the code you've posted. I hope it will be helpful to point some of these out, and provide a somewhat rewritten version:

Indentation is broken, but I guess this might just be problems pasting it into Stack Overflow

strftime is for formatting times, not parsing them. You want strptime instead.

In Python, True has a capital T.

You're defining the getDate function but never using it.

You would never exit your while loop, since you don't break after getting the input successfully.

It's considered bad style to use "camel case" for variable and method names in Python.

You use the word "older" in reference to the dates, but without a year you can't say if one person is older than the other.

You catch any exception thrown when you try to parse the date, but don't display it or check its type. That's a bad idea since if you've mistyped a variable name (or some similar typo) on that line, you won't see the error.

Here's a rewritten version of your code that fixes those problems - I hope it's clear from the above why I made those changes:

Thank-you very much! Yes its definitely more clearer than before from what I had. I'm using a intro to python book that doesn't really do into details of what modules/objects do and when/how to use them. I think it's time for a new and better one haha.
–
abcdpythonMar 14 '11 at 3:03