To whom it may concern. This code is from Dr. John Keyser.

gooddata = []

for singleday in datalist:
    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append({singleday[2], singleday[3], singleday[4], 
singleday[5]})

# 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?????????

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.

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


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.

God Bless:

James Lundy
jalu...@computer.org<mailto:jalu...@computer.org>
###################### Read in Data ################################
# Open file
filename = input("Enter the name of the file: ")
infile = open(filename, 'r')
#print(infile.read())






# Read in data
datalist = []

for line in infile:
    #get data form line
    date, h, l, r = (line.split(','))
    lowtemp = int(l)
    hightemp = int(h)
    rainfall = float(r)
    m, d, y = date.split('/')
    month = int(m)
    day = int(d)
    year = int(y)

    #put data into list
    datalist.append([day, month, year, lowtemp,hightemp, rainfall])



#Close file
infile.close()

###################### Analyze Data ####################################
# Get Data of interest
month = int(input("For the date you care about, enter the month:"))
day = int(input("For the date you care about, enter the day: "))
# Fomd jostproca; data fpr date
gooddata = []

for singleday in datalist:
    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append({singleday[2], singleday[3], singleday[4], 
singleday[5]})

# 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?????????

for singleday in gooddata:

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

avglow = sumofmin / numgooddates
avghigh = sumofmax / numgooddates


###################### Present results ################################
print ("There were", numgooddates,"days")
print ("The lowest", minsofar)
print ("The highet", maxsofar)
print ("The avaerage low has been", avglow)
print ("The average high", avghigh)


###################### Extra code for test #############################
# #greeting = "Howdy!<nl>How ar you today?<nl>I'm great!"
#lines = greeting.split('<nl>')
#for line in lines:
#    print(line)

1/01/2000,79,37,0
1/02/2000,79,68,0
1/03/2000,73,60,0
1/04/2000,51,26,0
1/05/2000,57,19,0
1/06/2000,59,46,0.08
1/07/2000,58,35,2.08
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to