Notes and Assignments

2017-04-28 CSV to HTML - HW

posted Apr 28, 2017, 6:55 AM by Samuel Konstantinovich   [ updated Apr 28, 2017, 8:03 AM ]

Your python programs can output HTML.

We can write a python program that prints a valid (includes proper HTML skeleton) blank website (the body is empty).

BODY = "Something here"

print """<!DOCTYPE html><html>
<head><title>"""+TITLE +"""</title></head>

""" +  BODY + """


Notice that you can use variables in your HTML string that make it easy to replace segments of your website.

Write a python function that converts a 2D list, into an html table. 
L = ['a','b','c','d'], [1,2,3,12], ['fa','bu','lo','us'] ]
toHTMLTable( L ) 
Would return the string:

   <th>a</th> <th>b</th> <th>c</th> <th>d</th> 
   <td>1</td> <td>2</td> <td>3</td> <td>12</td> 
   <td>fa</td> <td>bu</td> <td>lo</td> <td>us</td> 

-If you could ask for a built in function to help you with this task , what would that function be?
-Is there a repeated non-trivial task in this problem that would be best put into a helper function?

a) Write the helper function first
b) Write the toHTMLTable() function using that helper method.

Goal 2 - Homework due Tuesday May 2nd 8am. 

2010 SAT results:
2012 SAT results:

1 Export these as a CSV. 
2 Read the data into python. Don't forget to include your header on this assignment!
3 Split it up appropriately.
4 Add a new column! "Total Score", and calculate the total score for each row of the data.
5 Convert the to an HTML table.
6 Output a complete website with your name on top and the SAT stats in an HTML table. Do this to both CSV files and output the text to SAT2010.html, SAT2012.html.
7. Place the html files into the folder:  ~/public_html/02SAT/ 
( ~ means your home directory)

2017-04-27 CSV

posted Apr 27, 2017, 7:16 AM by Samuel Konstantinovich   [ updated Apr 27, 2017, 8:31 AM ]

More CSV file parsing!

Attached to this post are two files, one for linux, one for windows.

From Yesterday: 
Convert a csv string into a list of lists:
text =  '''a,b,c

1. Break it up line by line (split on new lines)
2. replace each line with a list (split on commas)

These 2 steps are absolutely critical. They are common, and should not take very long. If you dont remember study the following:

Lists = text.split("\n")
i = 0
while i < len(Lists):
  Lists[i] = Lists[i].split(",")

This is not a very long block of code, but if you don't understand a  part of it, then it might take you a long time to replicate.
altrernate loop:

Lists = text.split("\n")
for i in range(len(Lists)):
  Lists[i] = Lists[i].split(",")

Classwork (finish at home!)

Look at the data files that are included on the post (at the bottom), which columns are numerical?

We have:

Your goals:
1. Calculate the total height of all people in the list. (sum a column)
2. Calculate the average age. (average a column)
3. Calculate which person has the highest score (find which row) Then print out that person's information.

How do we convert the data file into some structure in python that would be easy to work with?


1. After splitting the data, take a small (3-4 line) slice of the list to work with. 
2. Make a function to calculate the sum of a column in a 2d list. Test it on some lists that you make before you test it on the real data.

Try to make a function to find the sum of the nth column of this list:

or, leave them as strings:

sumCol ( ListOfLists, n)  

This will make the whole lab much easier. 

2017-04-26 CSV Files

posted Apr 26, 2017, 6:47 AM by Samuel Konstantinovich

given the string:
data = """1,2,3,4,5
#remember three quotes will include newlines as \n, using one set of quotes will not. 

1. How would you convert that into a list of strings:  (newlines are just for ease of reading)

2. How would you convert that into a list of lists of NUMBERS:(newlines are just for ease of reading)

3. What if the 1st line of the data was a list of words:
data = """ID,age,height,width,score

How can you make a special case for the first line such that you get the list:

CSV Files are: Comma Separated Values
Some examples:



Real data can be found here:

2017-04-25 Files

posted Apr 25, 2017, 6:13 AM by Samuel Konstantinovich

Attached are two files with the same contents. The difference is that they are formatted for windows or linux/mac respectively.

DO NOT open/edit the files! It will potentially change the formatting.

Python can open a file using

Make a new file data.txt and paste in the following:

___________________copy everything after this line------------------
This is a text file.
There are things inside of it!
20 30 40 50
30.4 1.0 3.33 0.6668
___________________copy everything before this line------------------

in the same directory make a python file:

___________________copy everything after this line------------------
#Paste in this code, then test the 3 different read commands.
file = open("data.txt","r")   # r means read mode

#UNCOMMENT ONE of these:
#text =
#text = file.readlines()
#text = file.readline()
print text
___________________copy everything before this line------------------

In your notes:
Write a description of  what each of the read commands does. 

Now in python:
Use readlines, and you will notice that 2 of the list elements has a string of numbers.

Write some code to split those lines, and try to add the values together.
"20 30 40 50" 

Put that string (from your list of strings) in another variable to make it easier to play around with. 
It can be split up using either : split()   or split(" ")  

Your goal:
Try to add up the values. 

How do you convert a string to an int or floating point number?

Your final goal:
Download the text file attached to this post.
Find the sum of all of the values.

Extra goal:
How would you find the sum of all of these numbers if they were in a text file?

2017-04-24 Pair Programming

posted Apr 24, 2017, 5:35 AM by Samuel Konstantinovich   [ updated Apr 24, 2017, 10:34 AM ]

Classwork: This is meant to be started in class and finished at home, you should have it working by Wednesday morning. (You have 2 dojo days and 2 nights to make it work)

Homework: Submit these 3 questions on CodingBat.

Refresh your memory on python lists here:

PAIR PROGRAMMING! One keyboard/computer, one of you drives the problem solving, the other is typing. Every 8 minutes swap! 

note: that these functions do not return copies! They change the list. If you print the functions the output will be 'None'.

1. Write a function:   removeValuesFromXtoYList(L,x,y)  that will modify the list such that any values n in the list will, such that x < n < y, will be removed. Assume x<=y. (You may use the built in methods to take out the value, as that is a small part of this problem. Read the list method page to help out.)

bigHint: if you remove the first element, does the list have a first element now? What is it? Where did it come from?

L=[ 1, 3, -5, 10, -2, 0, -6.0, 0 , 1]
print L # would print [ 3, -5, 10, -6.0]

L=[ 1, 3, -5, 10, -2, 0, 2, 2, 3, -6.0]
print L # would print [ -5, 10, -2, 0, -6.0]

2. Write a function moveNegativeToEnd(L) that takes a list as a parameter. It moves all negative values to the end of the list. All non-negative values stay in the same relative order, and all negative values stay in the same relative order. The precondition is that all values in L are real numbers. You can use any list methods you find, as well as slices. I strongly urge you to look at the methods! 

BIG hint: If you get an infinite loop, what happens when you test it on [-1, -2] ? Trace through your code and see.

x=[ 1, 3, -5, 10, -2, 0, -6.0]
print x # would print [ 1, 3, 10, 0, -5, -2, -6.0]

y=[0, 1 , -3, 4.5]
print y #would print out:  [ 0, 1, 4.5, -3]

3. Write a function reverseWordsWithCapitals(L) that takes a list of strings. If any of the letters in a string are capital letters, that string should be replaced with the reversed string. Before you write this function, think about a good way to break it up. Strings with no capital letters are left alone. The order of the strings should not change. 
x = ['fish','Hey!','oOps','this is Sparta!']
reverseWordsWithCapitals( x ) 
print x # would print ['fish','!yeH','spOo','!atrapS si siht']

2017-04-20 HW

posted Apr 20, 2017, 6:20 AM by Samuel Konstantinovich

External Access to Sites:

Internal Access to Sites:


Everyone must fill this out:


posted Apr 19, 2017, 7:55 AM by Samuel Konstantinovich

Terminal Commands:
cd ..
cd directory_name

Create a public_html directory in your home directory.
Test this by connecting to

Create a 01homepage directory inside that directory.
place your html/css files in the homepage directory.

2017-04-07 HW

posted Apr 6, 2017, 7:54 PM by Samuel Konstantinovich

Codingbat problems:
ALL of the old problems should be done by the end of the break. 
However: Keep in mind the median score is completing them all, so your grade does get affected if you start to miss more than one or two.

New Codingbat problems: These should be done by the Friday after the break. You should have enough time in class to complete most of them.
Processing text:
 capitalizeSentence   (hint, split and a built-in string function can help you with this)
 pigLatinMultiple   (hint, split and your pig latin function from before can help you with this)

2017-04-05 Break Assignment

posted Apr 5, 2017, 6:57 AM by Samuel Konstantinovich   [ updated Apr 5, 2017, 8:02 AM ]

Break assignment Counts as a quiz.

Due Thurs after break 
Make an "about me" webpage
-Include basic "public friendly" information about you and things you like. No sensitive information. *discussion point*
-Use CSS to style the page and show off your creativity and technical skills.

Technical Requirements:
-There should be 3-4 paragraphs about you, and at least 2 different lists of things. Writing the content should be super easy, just write about stuff you like and things -Format the information using the HTML tags you have learned in a sensible way.
-Include images
-Do NOT include sounds
-Please make it a single page, not several linked together!
you find interesting. 
-Most of the style should be in the style tag, or in an external css file, NOT in individual tags.
-Demonstrate you understand how to research and apply style to your website

Asthetic requirements:
-Pick a color theme that makes sense, not random colors. can help you.
-Size your images to make sense in a browser window.

Optionally: You can ask to be judged and I will pick out the best web pages!

Goal: CSS is your friend
css file:
body {
background-color: black;
color: blanchedalmond;
p {
    font-size: 18px;
    font-family: cursive;
table {
    color: yellow;
    font-size: 32px;


<!DOCTYPE html>
        <link rel="stylesheet" href="stylesheet.css">
            body {
                background-color: tan;
                font-family: sans-serif;
                color: black;
                font-family: sans-serif;
                color: darkgoldenrod;
                font-size: 140%;
                font-family: monospace;
                border: 2px solid black;
                border-collapse: collapse;
                background-color: antiquewhite;
                color: saddlebrown;
                color: chocolate;
        <h1>B - Not a visa....</h1>
        <center>This is not in a paragraph.</center>
        <p>Bacon ipsum dolor amet tail shankle hamburger, pork loin kielbasa leberkas sirloin flank doner pork corned beef ham hock cow filet mignon pancetta. Salami picanha alcatra pork. Short loin chuck turkey kevin pancetta.</p>
        Also not a paragraph... default stuff here.
            <td><img width="100" src=""></td>
        <h1>WHOA! HTML</h1>
        <h3>smaller header</h3>
        <p>Frankfurter pastrami ball tip, landjaeger bresaola ground round burgdoggen. Shankle pig shoulder ground round strip steak hamburger spare ribs brisket tri-tip boudin ribeye bresaola kielbasa frankfurter ham.</p>


posted Apr 4, 2017, 7:26 AM by Samuel Konstantinovich   [ updated Apr 4, 2017, 7:31 AM ]

Small Group activity: 
New seats for today! 
1st, 3rd, and 5th student in each row, swap with the person in FRONT of you (They are behind your computer)

Common issues:

The value of the expression 
is:  "ab"  (with quotes)

The output of the statement:  
print "a"+"b" 
is:   ab    (without quotes)

print x    will print the value inside variable x.

print "x"  will print an x on the output. 

Classwork: You are collaborating on a fake quiz! You may use your reference sheet, but NOT the computer.
1. Work with 3-4 of your neighbors. 
2. Do not run the code! Do not run the code!
3. Agree with each other on the answers and EVERYONE write it down. (include the question)
4. After completing a section, compare that ENTIRE section with 2 neighboring groups.
5. Move on to the next section only after 2 other groups agree with you.

By the end of this everyone should have the same answers, and should be convinced that they are correct. 

EVALUATE EACH OF THESE: (The actual problems)
#I starting list and strings
s = "two fish?"
L = ["two","fish?"]
L2 = ["one","fish","two","fishs?"]

#II len
print "---LEN:---"
print len(s)
print len(L)
print len(L2)

#III indexing
print "---INDEX:---"
print s[1]
print L[1]
print L2[1]

#IV slicing
print "---SLICES:---"
print L2[1:3]
print L2[2:3]
print L2[:2]
print L2[::2]
print L2[1::2]

#V split
print "---SPLIT:---"
print "this is a test".split()
print "this is a test".split("s ")

#VI join
print "---JOIN:---"
print "wh".join(["o"," are"," you"])
print "an".join(["b","n","a"])

#VII split and join
print "---SPLIT+JOIN:---"
print "!".join("the only way to go?".split())
print "".join("bannana".split("an"))


#New Python Stuff (not on quiz yet)
print "---range:---"
print range(5)
print range(2,5)
print range(2,10,2)
print "---in:---"
print "a" in "fish"
print "i" in "fish"
print 5 in [1,2,3]
print 5 in [3,4,5]

1-10 of 43