Lecture 42: + HW

posted Apr 18, 2013, 5:37 AM by Samuel Konstantinovich   [ updated Apr 19, 2013, 1:42 PM ]
Notes:
some people had difficulty with the web page assembly, here is a different way of thinking about it.

head='''<!DOCTYPE HTML>
<html>
<head>
   <title>My Page</title>
</head>
<body>
'''
#create the main part of your web page
body= makeSomeHtml()#any functions that make content, tables etc.
body+=makeSomeMoreHtml() #any functions that make content,tables,etc

foot= '''</body>
</html>'''

webpage = head+body+foot

print webpage

Classwork: Extend yesterday's lab by not only printing the table, but making it more interesting by adding tags to random words.

Here are the data files for people that don't pay attention:
http://lisa.stuy.edu/~konstans/SAT2010.csv
http://lisa.stuy.edu/~konstans/GDP.csv
http://lisa.stuy.edu/~konstans/yankees.csv
http://lisa.stuy.edu/~konstans/studentdata.csv


EXAMPLE CODE FROM CLASS (4/19/2013) for SUMMING COLUMNS:
#You may Assume the csv doesn't have extra empty lines at the end
#You may Assume the csv has exactly one header with the names of each column (the first line)
f=open('studentdata.csv')
STEW=f.read()
f.close()


#get the total of the values in a specified column
def sumCol( data ,colName):
    s=data.split('\n')
    for i in range(len(s)):
            s[i] = s[i].split(',')
    sIndex=s[0].index(colName)

    tot=0
    for line in s[1:]:
            tot+= int(line[sIndex])
    return tot

#get the average of the values in a specified column*.
def avgCol(data ,colName):
    return sumCol(data,colName) / float(data.count('\n')    )

print avgCol(STEW,'SAT2010')
print avgCol(STEW,'SAT2011')
print avgCol(STEW,'requested salary')

#try to get the max value in the specified column
#try to get the line number of the max value in the specified column





Homework Reminder:
1. You must have your madlibs.py posted.
2. You must link your madlibs.py in your home.html
Homework Addendum:
3. You must post your improved table Lab (that we did today/yesterday) 
4. Link your table lab in your home.html  

Comments