[Tutor] Python Assignment Question
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Sep 24 22:16:23 CEST 2012
On 24/09/2012 20:20, Aija Thompson wrote:
>
> Hi!
> I've been working on this question for a long time and for some reason it's just not clicking.
> 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.
> 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'
> 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!
Your code is basically unreadable in Thunderbird but as I pinched
another of your threads I've had a go at untangling it.
What you're doing is getting an index into a string. You want to get an
index into a list. You can also simplfy the whole structure so search
the web for "python two dimensional lists", without the quotes of course.
HTH.
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list