# [Tutor] Python Assignment Question

Dwight Hutto dwightdhutto at gmail.com
Mon Sep 24 22:24:22 CEST 2012

```On Mon, Sep 24, 2012 at 3:20 PM, Aija Thompson <aijathompson at hotmail.com> wrote:
> Hi!
>
> I've been working on this question for a long time and for some reason it's
> just not clicking.

Algorithm is the appropriate approach. That's what makes it click.

>
> I'm not sure if my loop for the question is the right one, or if I'm even on
> the right track.
>
> We're supposed to make a program that counts the number of days into the
> year it is if you input a date. Not including leap years.

We'll leave leap years alone for now then, but there are special years
for that input which could be used as a count variable.

>
> This is what I have so far:
>
> months = 'January, February, March, April, May, June, July, August,
> September, October, November, December'
> daysPerMonth = '31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31'
>
> #shorterMonths = 'February, April, June, September, Novmeber'
> #longerMonths = 'January, March, May, July, August, October, December'

I'd suggest using a dictionary with the month as the
identifier(month_dict = {'january' : 31, 'february': [28,29]}, and an
integer as the value for each static count of months.

>
> month = raw_input('Enter the month: ')
> day = raw_input('Enter the day: ')
>
> for x in month:
>         whichMonth = months.index(x)
>         monthNumber = daysPerMonth[whichMonth]
>         dayYear.append(monthNumber)
>
> I was hoping to make a loop that would check which month it is and compare
> it to the second list I made with the number of days in that month. I don't
> know if I've made that clear to the program or not. Either way, I feel
> pretty lost at the moment.
>
> Any help would do!
>
> Thanks!
>

But in the end, you just want to count days.
So you could iterate through the dictionary's values_of days in each
month, up until the month and the date matches(loop stops), while
using a day_count += 1 in the loop.

Just check for the value of the month, and the number of the day to
stop the loop count.

--
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
```