[Tutor] Python Assignment Question
aijathompson at hotmail.com
Mon Sep 24 22:56:14 CEST 2012
Yeah this is my first assignment and I've never worked on anything programming before.
I am working in Python 2.7
The shorter and longer months thing is just a not to myself, that is why it has the hash tag before he sentence.
But my initial plan was to make a string of months and a string of the number of days in those months and have them compare to each other. So it would go through a loop and if you typed in February it would look through the list of numbers and see that January comes before and has 31 days and would add the number of days in February it has been. For instance 22. And it would add 22 to 31 to come up with how many days it has been this year so far. So I've been trying to make that work some way but I have so far been pretty unsuccesful. Does the way I'm even thinking about making the loop make sense?
> Date: Mon, 24 Sep 2012 16:48:56 -0400
> From: d at davea.name
> To: aijathompson at hotmail.com
> CC: tutor at python.org
> Subject: Re: [Tutor] Python Assignment Question
> 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]
> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor