[Tutor] Re: Calendar question

Kristian Zoerhoff kristian.zoerhoff at gmail.com
Wed Apr 6 16:23:29 CEST 2005


On Apr 6, 2005 7:12 AM, John Carmona <jeannot18 at hotmail.com> wrote:
>
> Now I have got another question raising from this script. Would it be
> possible for the person doing the input to use either the months name in
> writing and also in number?

I can think of 2 ways to accomplish this.

1. Try to convert monthString to an int, use the lookup if that fails.
This might be a good way to learn try/except processing.

2. Just double-up your dictionary to include a second set of keys:

{'1':1, '2':2 ...}

and just use your existing lookup method, unmodified. You wouldn't
have to worry about string->int conversion after raw_input this way,
so it's cleaner to implement.

-- 
Kristian

kristian.zoerhoff(AT)gmail.com
zoerhoff(AT)freeshell.org


More information about the Tutor mailing list