MKS2 - Introduction to Computer Science

Spring 2013 -- Peter Brooks

Extra credit paper (optional), due Fri (6/14) midnight Requirements are here.
Digital circuits The Digital Circuit Simulator is here
Final Project, due Wed. 6/5 midnight  Here are the requirements for a complete final project.  Remember to submit the project to the Class Project List (see requirements).
SPOT SPOT is a computer language designed to be similar to the "assembly" language for a simple micro-processor.
When I created this language, in 2005, and taught it to seniors taking my Python class, I challenged them to come up with acronyms for SPOT. One of my students, Jena, took it on as a challenge.

SPOT is also now available on Marge for new, improved response times while in class!

Here is a machine-language version of a simple SPOT program.

Big Project (and Wed. midnight milestone) Initial Project ideas/requirements are here.
What I'd like to see on the homework server by Wed (5/29) is this.
The LittleCalculator and some of its Python code.

Here are lists of student names for each of the classes (right-click and download):
Answers to the Python test are here.  
Data Presentation Project, due Sun (5/19) midnight Requirements: Each member of your group needs to put onto the homework server:
  1. an HTML link to your Query-page into the Comments-to-Teacher
  2. 1-3 sentences on who did what on the project also into the Comments-to-Teacher
  3. upload the Python program 

Presentation

Here is a sample presentation project that I cooked up for the SAT data...(and here's the Python program that handles it).

Here's the new/improved guide to CGI programming with forms.

Note: There's a quirk when working with the PythonWebServer at home: If the Python program you write reads a data file, then put your Python program into the cgi-bin directory (a subdirectory of the directory containing the PythonWebServer.py file), but put your data file into the directory containing the PythonWebServer.py.  Despite the fact that your program and the data files are in different directories, when your Python program is run by the web-server, it can still open the data file using the simple open(filename,'r') command, as if the data file were in the same directory. 

Homework due on Sun (5/12) midnight Create a web page that has at least 3 user-interaction fields (text box, checkbox, drop-down menu, button, radio buttons), and a Python program that will be sent the data that the user fills in and does something interesting with it.  Put a link to the web page, and your partners names, into the Comments-to-Teacher (just like you did for your homepage).

Mr. Holmes has provided, for us, Tiny Steps Toward Enlightenment -- a guide which will step you through the successful creation of such interactive webpages.

Practice Python Test Remember: we have a Python test on Friday (5/10).  Here is last year's test.  I'll be posting answers to these questions shortly (watch this space...).
Web page Queries Here is a guide to web page "forms" -- web pages with text input fields, and checkboxes, and drop-down lists, etc., and how to write Python programs to handle their uploaded contents.
Homework, due Sun (4/5) midnight Anagrams!
Logging into marge from home To view or fix files and directories directly on marge, you can use a program like PUTTY (freely available), to log into marge as if you were in a terminal window in the classroom.  Here is a guide to using it from Rabia Akhtar, a student in Mr. Brown-Mykolyk's class.
Sick today (Fri) as well (not badly, I just didn't want to cough at y'all). Friday: Quick (or not so quick) class exercise: (Here are the answers, but try it yourself first)

1) Download the SAT scores file below (if you haven't already) into your marge account.

2) Clean the file: removing any non-school data, removing schools that have no SAT scores, fixing the lines with schools that have commas in the middle of their names so that you can use their SAT data without problems.  If you're not succeeding at fixing the lines with the schools that have commas, then just remove those lines/schools from the datafile (serves them right to clutter their names with commas).  Write the cleaned version to a file.

3) Read the cleaned file and create a dictionary called dSchools with the school name as the key, and the total SAT score as the value.

4) Invert dSchools, creating a new dictionary called dSAT whose keys are the distinct total SAT scores, and whose value, for a particular key, is the list of schools with that SAT score.

5) Retrieve the list of distinct SAT scores from dSAT by asking for the list of its keys.  Sort this list.

6) Print the school(s) (guess!) with the highest SAT score, and the one(s) with the lowest, and the one(s) with the median score.  If there are an even number of distinct SAT scores, choose one of the two middle ones.  Remember: the point of inverting dSchools is that there may be several schools with the same SAT score, and so the values in dSAT must be lists of schools, even though most schools have SAT scores that are different from those of other schools.

Sick today (Wed).   Quick class exercise (which might be useful in the next homework assignment):

Given the following list whose elements are little 2-element lists:
L=[['Harry','good'],['Ron','good'],['Draco','bad'],['Hermione','good'],['Voldy','bad']]

1) create a dictionary called dNames whose keys are the names and whose values are 'good' or 'bad', so that if I know the name of one of the characters, I can look up whether he/she is good or bad.

2) using dnames only (not using the original list), create a new dictionary called dGoodness  whose two keys are 'good' and 'bad', and the 'good' key has the value of the list of people who are good, and the 'bad' key has the value of the list of the bad folks.  So, I can use the dictionary to get a list of all the 'good' or 'bad' people.

This is an exercise in "inverting" a dictionary -- converting the keys into values and vice versa.  This is occasionally very useful.

Data! Here are two large-ish data files, which you can download with the usual right-clickery.
1. A dictionary of about 80,000 English words.
2. The New York City schools' SAT scores, before I cleaned the data of some of its problems.
Dictionary homework due Mon, 4/29, midnight
Read and do the exercises in Mr. Holmes' Dictionary exercise page.  Do the exercises in the Python shell, and then save the shell session (using File/Save As) and submit that to the homework server.
Date/Time + Random Phrase homework problem due Sat (4/27), evening/midnight

Every member of your team must have the project functioning in his or her own account on marge
So, test, test (and also, test).
Your group should create a Python program, running on marge that, at minimum, displays the current date and time and a random phrase -- the random phrase (or at least a part of it) must come from a file of such phrases that reside inside a file that the Python program reads.  Your intent is to make the web page generated as creative as possible to induce the user to come back and ask for the page again.  That should include creative formatting as well as intriguing text, etc.  The text that you select randomly from should be in a file by itself, that your Python program reads and displays part of.

1. Submit the Python program file (not the text file of phrases/text) to the homework server
2. Put into the Comments-to-Teacher: 
    a)  the html link to your Python program on marge, as in:
              <a href="http://marge.stuy.edu/~peter.brooks/whatever.py">Here 'tis, Mr. B</a>
    b) The names of all your team members.
Try a simple Python generated web page: Here are a new set of instructions from Mr. Holmes on how to start creating simple Python-generated web pages.

Here are two (almost identical) simple Python programs that you can use to copy from and expand.  One is for Windows and the other for Mac/Unix.  Download (by right-clicking, and "Save As...") the appropriate one for your system, and change the suffix from ".txt" to ".py".  On a Mac or Unix system, you'll also have to change its file permissions to "executable", which you can do with the UNIX command chmod +x *.py, when you're in a Terminal window in the same directory as the file.

Download, install and test the PersonalWebServer -- if you do not have a web server running on your home computer. Instructions are here.  DO NOT use Internet Explorer as your browser when working with the PersonalWebServer.  If you have a Windows system, use Firefox or Chrome instead.
Homework, due on Tues (4/16) midnight (actually Tues 11:59:59 pm) is here.  
File Reading/Writing quick tutorial is here.  
Here was the Liz Quist.
If you did not meet your expectation for the minimum comfortable grade on the Quist, then go to the DOJO and solve the hardest (for you) of the problems there or get help.
Quick Looping exercises are here due Tues, midnight.

CodingBat's List-2 exercises -- answers. There are other solutions to these exercises, in addition to the ones I'm providing.  I'm including these as tutorial.  Try to understand some of these solutions (not necessarily all of them), but at least one for each exercise.  Those of you who are more comfortable with the material so far, study the advanced Python techniques I'm also including, like "list comprehensions", the reduce() function,  lambda-expressions, and if-else expressions.
List (and string) homework due Wed, 4/3 midnight Some of these problems are challenging, but I'd like all of you to try them.  Leave comments inside your code as to how far you got. And, as I mentioned in class, DO NOT submit any code that you haven't tested!  For problem #3, you'll need to calculate a value and put that value into the Comments-to-Teacher.  Despite this, have a great spring break.  Answers are here.
The Daily Digital will go live when we return from Spring Break (April 3) Each day, one of you will give a very short (5 minutes or less) report on a news item about the digital world (though preferably not about gaming unless it's astounding).  You must understand the news item and report on it in your own words.  It can be about:
  • new computer hardware or digital capabilities (e.g. a robot which can dance hip-hop)
  • a software item (e.g. a program which can predict which songs will become popular), 
  • an economics item (e.g. the effect of cheaper memory on people's lifestyles), 
  • a political item (e.g. autonomous drones and the military)
  • lots of other possibilities

It can be serious or humorous, but it must be true.  You will also put a one or two sentence summary onto your period's Digital Daily Google Doc, with a link to the source.
Here are some sources you can tap into, although many others are fine: Slashdot, ACM TechNews, CNET Tech News.

Answers to the in-class list bar-graph exercise We had to do bar graphs: horizontal at first, and if that wasn't hard enough, then vertical.  Here are my answers.
Thurs 3/7: In-class practice using CodingBat CodingBat is a cool site to practice Python on.  Go to its Python area: http://codingbat.com/python. First, get used to the way it works by going to the String-1 exercises and trying to code: hello_name.  
In String-1 do: first_half,   without_end,   left2
In Logic-1 do: love6 
In Logic-2 do: lone_sum
In String-2 do: double_char,  count_hi,  count_code
More string exercises homework, due Sat. 3/9 midnight. Yet More String Exercises, where you'll finally be using the machine to decrypt secret messages.
(My) answers are here.
In-class string exercises And the answers...
References for string slicing, functions and methods 
String Exercise Homework, due Sun 3/3 midnight. It's here.  We'll be searching for things, writing secret messages, and classifying files by their contents.
Here are the answers.
Homepage VOTING!  All votes due Sat. 3/2 midnight. Here's the Homepage Contest.  Cast your votes for 1st and 2nd place in your Period, in the Comments-to-Teacher, in the "Homepage Voting" homework slot.
Homework due Mon. 2/25 midnight Do you want your homepage entered in the class contest?  For the "Enter contest?" homework slot: write "Yes" or "No" in the Comments to Teacher.
A fix for Mac users. If you're a Mac user and  having difficulties with IDLE (freezing, burning, crashing, whimpering) heed this message:

Some MacOS users have reported IDLE crashing often. (Seems to happen mostly with OSX version 10.6)


If this applies to you, try downloading this version from the Python website:
Python 2.7.3 Mac OS X 32-bit i386/PPC Installer (for Mac OS X 10.3 through 10.6 [2])
...and installing it. It should overwrite your existing version and remedy the crashing problem.
Homework: python exercises, due Wed. 2/20, midnight. Here are the exercises.  Create a .py file, and submit that to the homework server. Since there will be several homework slots, be careful to submit it to the "Python #1" homework slot.
Reference- (crib-) sheets Here's Julie Kim's Study sheet (as of 2/16/13)
Here's Mr. Brooks' Python crib-sheet, only a small part of which we've covered so far.
Homework: Create your own homepage, due Tues, 2/19 midnight Create a homepage, about you or one of your interests. The goal is to make it creative and interesting.  Call your html file: homepage.html.  Feel free to get ideas from anywhere, BUT DO NOT COPY and PASTE from anywhere. If you want to borrow (steal) an idea, understand how it works first and then type it into your homepage yourself.  Copy (upload) your homepage to Marge, into your public_html  directory there (re-create that directory if you haven't already -- remember that when Marge crashed, she ate all public_html directories).  Once you've done that, your homepage will be accessible to the world at the address: 
http://marge.stuy.edu/~your_account/homepage.html.  For instance, here is the url for my homepage: http://marge.stuy.edu/~pbrooks/homepage.html  TEST YOUR URL!!!

Then, on the homework server, in the Comments-to-Teacher, create an HTML anchor tag, like 
<a href="http://marge.stuy.edu/~pbrooks/homepage.html">Beware!</a>
and also tell me whether or not you want your homepage entered into the class competition.  Then submit that homework (MAKE SURE you submit it to the "homepage" homework slot!).  Then, go back to the View your Homework menu, and TEST your link.

If you are having problems viewing your homepage.html file after you've uploaded it to Marge, view this video...

Quick overview of the languages that the browser knows... HTML (of course), and CSS (Cascading Style Sheets), and Javascript.  Take a look here (and View its Source, if interested).
Download Python... Read this before downloading...
  • The Python official site can be found at http://www.python.org, and the download page is at: http://www.python.org/download/.  
  • We want to use version 2.7.3, not 3.3.0. Why?  Ask me in class.
  • Windows folks: you need to check whether you are using a 32-bit version or 64-bit version of Windows.  Try to find your Control Panel, and bring up the System page, which should tell you which version you're using.  Then choose the right Python download file.
  • Mac folks: Try to figure out which version of OS X you're using, and choose the appropriate Python download version.
Homework #1: due, Sun, 2/10, midnight
New instructions because our classroom server computer crashed...
  1. Build a web page according to the following design:
  2. Create a web page that looks like this.  And no, you can't just put this picture into the center of your web page.  Nice try.
  3. You may customize it a little, by using a different picture for the table, and any destination you please for the "Nirvana" link.  You may also change the text, and colors, but keep the general structure (look/placement of things) of the page.
  4. Use a picture that is NOT your own file/picture -- in other words, use a picture that's out there on the internet.   Your image tag should refer to a picture on the internet.
  5. Go to the homework server, when you Submit Homework, and upload your HTML file (you'll press the "Browse" button to find it on your hard drive), rather than the using the instructions I gave in class about creating an HTML "<a" anchor tag in the Comments-To-Teacher.
Working with images and hyperlinks Mr. Brooks: Create a web page about Albert Einstein.  You may use the picture here located here (http://marge.stuy.edu/~pbrooks/einstein.jpg).  Find and include a quotation from Einstein on the page, and a hyperlink to the source (page) of that quotation.

Mr. Holmes: Instructions here: http://www.davidmholmes.net/Bard/apprentice2/lessons/01_html/picturesWithoutMarge.html

Using color in HTML Here's a short explanation about using colors.
HTML & FileZilla Here are some good sources for HTML guidance:
Here's FileZilla: http://filezilla-project.org/download.php?type=client
First task: fill out your Profile on the Homework server.
  1. Go to the main class link page (http://www.micromind.com/stuy)
  2. Click on the Homework/Grade server link
  3. Choose the Profile menu item
  4. Choose your period and name
  5. Log in with your 4-digit Stuy ID as your password
  6. Fill out your email address, home phone #, and preferred first name only, DO NOT CHANGE YOUR PASSWORD YET.
  7. Save: (Change Profile button)...
  8. (optional, but recommended): now you can change your password for this Homework server, if you want.
  9. REMEMBER this password!
Help, in general
  1. AIS Tutoring is available for this course every Thurs (some some exceptions) after school (3:45) in room 325.
  2. Help from Mr. Brooks: Feel free to come and see me during periods 3, 4, 8 or 9  in room 301 (no appointment is necessary, but a warning is welcome),
    or, by appointment beforehand: just after school in room 401.
  3. If you need additional help, we can set you up with an Arista tutor.  Please see me.  However, this is unlikely to be successful right before tests, so let's arrange this further in advance.
Sending email to Mr. Brooks:
1. Use the correct address in the right-hand box
2. You MUST include your name in the subject line or body of the message, otherwise I won't know who it's from.
Period 2: mks2-s13-2@micromind.com
Period 5: mks2-s13-5@micromind.com
Period 6: mks2-s13-6@micromind.com
Period 7: mks2-s13-7@micromind.com
Stuyvesant bell schedule  
Homework/grade server  
Support Wikipedia