On 09/24/2012 03:20 PM, 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!                                         
>

Please don't send an html message;  this is a text mailing list, and
your text is hopelessly mangled.

For the benefit of others, I reformatted the code and enclose it here,
with tabs turned into 4 spaces.

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:
    print "x = ", x
    whichMonth = months.index(x)
    monthNumber = daysPerMonth[whichMonth]
    dayYear.append(monthNumber)

is this your first assignment?  Have you worked in any other programming
language before learning Python? Are you working with CPython 2.7 ?

Most of this code makes no sense to me at all.  Why isn't months a list
of strings?  Why isn't daysPerMonth a list of ints?  (I'm assuming that
shorterMonths and longerMonths are vestigial code.  If not, the two
spellings for November would surely cause troubles.

Why do you define day as a string, and not an int?

And why is the loop looping through the characters in the specified month?

Have you tried to describe in English how to solve the problem?



-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to