On 24/02/18 20:00, James Lundy wrote:
To whom it may concern. This code is from Dr. John Keyser.

Please arrange for him to go on a programming course :-)



gooddata = []

for singleday in datalist:
     if (singleday[0] == day) and (singleday[1] == month):

Yuck, unneeded brackets disease.

         gooddata.append({singleday[2], singleday[3], singleday[4], 
singleday[5]})

That looks like a set to me.


# Perform analysis
minsofar = 120
maxsofar = -100
numgooddates = 1
sumofmin = 0
sumofmax = 0

# so singleday in datalist is a list while singleday in gooddata is a 
set?????????

Seems like it.


for singleday in gooddata:

     sumofmin += singleday[1]
     sumofmax += singleday[2]
     if singleday[1] < minsofar:
         minsofar = singleday[1]
     if singleday[2] > maxsofar:
         maxsofar = singleday[2]

Could this be a bug in my Pycharm 3 compiler I have had mixed experiences 
running the code.

I very much doubt that.


An insertion of a space after for singleday in gooddata: line 54 caused the 
program to run as desired, once, since other runs cause the error

Really, I don't see how?



Traceback (most recent call last):

   File "C:/Users/Dad/PycharmProjects/TopDownDesign/WeatherDataSpecialDay.py", line 
56, in <module>

     sumofmin += singleday[1]

TypeError: 'set' object does not support indexing

persist.

I will attach the code and test file. Please allow me to thank you in advance 
for answering this query. I am new with Python and would appreciate any advice.

Put print calls into the code that you don't show above. This should show what gets written to the datalist and it's type, ditto for the gooddata list. I think you'll find that the code "works" when an invalid day and month gets input, yet produces the traceback when a valid day and month is input.


God Bless:

James Lundy
jalu...@computer.org<mailto:jalu...@computer.org>


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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

Reply via email to