Intro to Comp. Sci  (year) - 2

Spring 2019 -- Peter Brooks

All the projects The link page is up with all the pages that are fit to link.  Anyone wanting to opt out of the link page should send me email to that effect.
Assembly language! Here's is a simplified version of what an assembly-language looks like: Spot.  Here's a old student word-smith making up possible SPOT acronym meanings.
Extra credit projects (optional) due Sun, 6/16 midnight  
Monday, June 10 Those who have handed in their project by the original deadline (Sun night) can show them off to their neighbors and future fans.  Otherwise get your projects finished by tonight.
Problems with Lisa? No problem.  Instead of lisa.stuy.edu, you can use homer.stuy.edu, or bart.stuy.edu or marge.stuy.edu. They should all work identically, including with FileZilla and putty and ssh and WinSCP, and you can test your programs with them in the same way.  Your public_html directory is accessible in the same way by all 4 servers: lisa, homer, bart, marge.
Problems with bad characters Some editors and web authoring tools, as well as the Windows version of IDLE put characters inside .html and .py files that UNIX systems are allergic to.  Here is a Python function called Fixit(infile,outfile) in the file RemoveBadChars.py that creates a clean file from a dirty file.  Let's suppose that you have a suspect file called Fred.html that may have bad chars in it.  Download RemoveBadChars2.txt, change the name to RemoveBadChars2.py and bring it up in IDLE and in the IDLE shell, execute: FixIt('Fred.html', 'FredFixed.html') and it will tell you if there were bad chars and will create FredFixed.html without them.  If there were bad chars, then remove Fred.html and then rename FredFixed.html -> Fred.html. You can do the same with any Python files that are suspect.
Project hand-ins Your project deliverables:
1.In the Comments-to-teacher:  a working URL for your project.
2.A written dscription of the project development experience, including how the work was divided (if duo), problems yet unsolved, problems overcome.  Must be done seperately by both members of the (if) duo team.
Keeping score in web interaction Using the <input type="hidden"  HTML tag to keep score and keep a history of previous pages that your user had just visited.
Here's a demo of it.
Here's the Python program.
Here's the first HTML page (input_hidden_1)
Dictionaries Read this dialog to see how to deal with dictionaries.
Deadlines/tests

The remaining tests/deadlines for this semester:

  1. Test on all of Python/HTML, Fri. June 7
  2. Deadline for project submission: Sun night, June 9
  3. Deadline for optional extra credit project: Fri night, June 14
Message from the csDojo folks Read this to understand what a remarkable organization the csDojo is.

You can apply here to become a senpai in the Dojo.  Application deadline is Monday, 6/3 midnight.
Python Web Server A web server of your own.  Installation and usage instructions.
Project Proposals, due Thurs, 5/23, midnight Write your proposal into the Comments-to-Teacher.  Answer the following questions:
1. solo or duo?  If duo, who is your partner?  Also if duo, both of you MUST submit project proposals (probably identical)
2. a quick description of the website you're planning
3. If you're processing information obtained from elsewhere on the net, where is it coming from?  Have you obtained it and looked at it to make sure that you'll be able to write a Python program to access that data that you'll deliver to yor users?
4. Why will the user return (possibly repeatedly) to your site?  What value will the site have for the user?
Homework -- first interactive page.  Put a link to your working html page in the Comments-to-Teacher and also upload your Python file.  Due, Fri, 5/24 midnight Additional requirements: 1) Your program should never crash; 2) Informative message to the user if she doesn't provide you with the information you need to create an adequate and correct letter.
 
Create two files in your public_html directory: an HTML page called "letter-form.html" asking a set of 3 questions used to generate a letter, and a Python program called "letter-writer.py" that processes the data when the button is pressed and sends the typical web page below:

letter-form.html looks like this: letter-writer
The webpage response should look like this: written
Form input docs
Great previous student projects  
First interactive web page: Html is here.  Python is here.
The causes of (and fixes for) the dreaded ISE
Internet Server Error
Monday's classwork problem solved Here
Starting on dictionaries

Classwork: create a program called Eng2Fr.py that you can call from the terminal command line to translate an English word to a French word.  These (below) are the 6 word translations that it should be able to do.  You may not just have 6 IF/ELIF statements!!!  Use lists!

  1. cat -> chat
  2. kitchen -> cuisine
  3. computer -> ordinateur
  4. cool -> cool
  5. boredom -> ennui
  6. end -> fin

For instance:
$ ./Eng2Fr kitchen
cuisine
$ ./Eng2Fr hello
Cannot translate hello

Here is the answer using dictionaries.

As pre-advertised, I'm out today (Thurs.)  Homework due at the end of today (Thurs, midnight). At the end of yesterday's session, I asked you to create a program called flen.py which printed the size of the file named on the command line.  Assume that you have a file called fred.txt whose size is, say, 208 bytes (you can get the file sizes of files in your directory using the Unix command ls -l).  Then once you've completed flen.py, you should be able to execute the following two commands:

$ ls -l fred.txt
-rw-r--r-- 1 pbrooks sudo 208 Apr 7 2016 fred.txt

$ ./flen.py fred.txt
208


For today, improve on flen.py by creating its successor: mywc.py.  It will do much the same thing as the built-in Unix command: wc ("wc" once stood for "word count")Try running the wc command on the command line by giving it a filename of an existent file.  It will give you 3 numbers: the number of lines, the number of words and the number of characters in the file (as well as the filename).  Try to duplicate the functionality of wc with your own mywc.py.  Then you can call both of them to see if they produce (approximately) the same results:

$ wc fred.txt
5  42  208  fred.txt
$ wc voldy.txt
wc: harry.txt: No such file or directory

$ ./mywc.py fred.txt
6  42  204  fred.txt
$ ./mywc.py voldy.txt
mywc: voldy.txt: No such file or directory


In other words, the behavior of your mywc.py should mimic the behavior of wc. Also, notice that the numbers aren't the same.  As long as they're close (within about 1% for the number of characters), that's all right.  When I come back, ask me about this.

Submit this file (mywc.py) to the homework server, along with any comments about difficulties.

If you've finished, improve mywc.py by allowing it to take many filenames on the command-line, and reporting on all of them (wc can also do this).  For instance:

$ ./mywc.py  fred.txt  voldy.txt  harry.txt
6  42  204  fred.txt
mywc.py: voldy.txt: No such file or directory
27  210  1044  harry.txt
Command-line execution Here's a quick guide to executing your programs from the command-line.
Character frequencies homework due Mon. 5/6 midnight Using the Declaration of Independence, find the 3 most frequently used letters and the 3 least frequently used letters (this is case-indepndent, namely a capital "T" and a lower-case "t" are considered the same letter) and provide the following statistics in the Comments-to-Teacher (also upload the program you used):  The percentage of all of the letters in the document used by each of those 6 letters.  For instance, if "f", "r" and "e" were  the most frequently used letters, and "q" "u" and  "y" were the least, then you'd report the following:
f: 4.81%
r: 4.60%
e: 3.96%
q: 0.12%
u: 0.11%
y: 0.09%

BTW, the formatting for displaying a floating point number A to 2 decimal places with the percent-sign after it is:
print("A: %.2f%%" % A)
Note the 2 "%" chars next to each other means print a single "%" in the output.  The statement above can be confusing because the 4 different "%" signs in it mean 4 different things, and the meaning of each can only be understood in context.
CSV (comma-separated-values) files

We'll be reading and digesting CSV files.  Here are a few to download.  Download them, look at each in a spreadsheet program, and also in an ordinary text editor (not Google docs, or MSWord).
- sample.csv
- grades_small.csv
- grades_large.csv
- grades.csv
- 2012_SAT_Results_small.csv
- 2012_SAT_Results.csv

Here's the code for calculating the average of a CSV file's column.

Here's the code/explanation for processing the SAT results file.

Here's a simplified version of the SAT file with just the math scores.

Retest on Wed (4/17)! As I mentioned in class, I will grade exactly one of your 2 tests: Fri (4/12) or Wed (4/17), your choice (if you were not absent on Fri).
The test is here.
My answers are here.
Friday's String/List test Here's the test.
Here are my answers.
Let's play with file-reading Here's the Declaration of Independence.
Here's a list of English words (lots of them): dictall.txt
Are you interested in taking APCS? ...then here are words of advice from Mr Holmes (a good read).
Some Python topics Information about Python topics beyond basic string/list processing: Dictionaries, File reading/writing, CSV files, Python/HTML processing and others.
String and List exercises
Due Mon, 4/8 midnight
Here's a little review on the split() and join() string methods.
Here's the main homework.
Here's a few (optional) additional exercises, for fun.
Here are my answers.
More (and more interesting) Codingbat problems for Tues, 4/2 classtime

Mr. K has created a bunch of Codingbat problems that you'll find here: https://codingbat.com/home/konstans@stuy.edu/all
Here are some of Mr. K's problems you should do. If you finish these, try others.  Remember: I get stats on which problems you've solved.
- Sum of Powers
- CountVowels
- MyUpper
- MyCapitalize
- XYBalanced
- RemoveFromString

String formatting
Exercises due Mon  4/1 midnight
for print() and other output (to output files):
There are two types of string formatting, old/single-character: and new.
Exercises are here.  Additional exercises added on Thurs night, deadline extended to Monday night.
For the exercises, do not game the questions -- for instance, don't use int() or float() or str(), or any other Python built-in function that will make the exercises trivial.
Here are my answers.
Recursive functions exercises, due Sat 3/23 midnight  
Loops and Strings exercises, due Mon 3/11 midnight (we'll cover these in class tomorrow) Here they are.  Put your answer file onto the homework server.
CodingBat Create an account on CodingBat.com.  Here are particular instructions:
1) When asked about your name (the 3rd of 3 questions in account creation), compose the following answer consisting of your year,class period and name -- if your name is John Smith and you're in period 6, then your answer should be 19,p6,smith,john.  Please do this exactly(otherwise I cannot sort and make sense of the results).

2) When finished with creating an account, go the prefs tab (upper right on the screen), and enter pbrooks@micromind.com into the "Teacher share" input box, and press the "Share" button.
Personal Homepages Are Here!
Votes due Sun 3/3 midnight.
  1. View ALL of the pages for the students in your class (not just the ones in yor competition).
  2. Post, in the homework slot, your vote for the 1st and 2nd best, by name of student. 
  3. Do not vote for yourself -- will not be counted.
  4. No vote-buying, no threatening, NO COLLUSION!
Python resources
PYTHON!! Download the latest version (3.7.2) of Python to your home computer from: https://www.python.org/
Personal homepages are due Tue, 2/26 midnght
  1. You'll need to upload your homepage(s) to your public_html directory
  2. then test your URL that you will publish to the outside world.  For instance, if your login id is "fred" and your homepage is "harry.html" then the URL will be https://lisa.stuy.edu/~fred/harry.html.  Make sure you TEST YOUR  LINK
  3. Into the homework server's assignment slot's Comments-to-Teacher, write your URL and say whether you want to enter the class competition or not.  If you forget to specify this, I'll assume that you want to compete.

 

 

Web Authoring tools Recommendations from
Period 3
Period 4
Period 5
Great Homepages from history  
Unix and HTML keywords for Friday's quest  
Transferring files between your home computer and Stuy
  • Here's FileZilla.  You want to download and install the FileZilla Client
  • For Windows, I'd also recommend WinSCP (an equivalent file transfer program).  Main website here.
And now a word from one of my A.I. students...
Hey folks!
My name is Joan Chirinos, and I’m the president of the Stuy Competitive Computing Club.

"What’s the Competitive Computing Club???"

Good question! As underclassmen, y'all will spend a chunk of your time learning how to write Python. 
We will also use this knowledge in a number of fun activities, including mini-competitions! 
With your immense Python knowledge, you can even go to PClassic, a larger and more structured CS competition!

If this sounds interesting to you, please fill out the form below. I will be emailing you shortly about our first meeting!

https://goo.gl/forms/AUjD2nKrBmNvJVCw2
For Wed, 2/13 (midnight): web authoring tools/editors Find and recommend a web-authoring tool: one that allows you to create a web page without actually writing the HTML code yourself.  However, one feature that you'll want is to be able to edit the HTML code itself, if you want, while you're creating the page.  In the Comments-to-Teacher, provide the URL,cost (if not free), and a description of the editor, and whether you recommend it or not.
CSS and Javascript A tiny demo of CSS and Javascript.
Gedit Mac installation suggestion from a student On installing GEDIT on a Mac, from Anna Yuan: http://mac.softpedia.com/get/Word-Processing/gedit.shtml#download;
After downloading it, don't drag it into applications like it says because it won't open. Just right click it and open it that way. :)
Second homework: due Thurs, 2/7 midnight Create an HTML file (page) that looks like this.  You must write all of the HTML yourself (do not use any webp-age authoring tools).  The picture should be somewhere out there on the internet, as well as the page you've linked to.  Upload the file to the homework server slot, as well as any (optional) comments about any problems.  Then go to View Homework, and see if you've succeeded in uploading.
Some HTML/CSS reference and tutorial pages from past students In addition to W3Schools, which is a master reference site, the following have been suggested:
Lynne Wang: HTML Cheat Sheet and another HTML reference with tutorial suggestions
Puneet Johal: Another HTML tutorial site (with some good information on fonts, etc.)
Codecademy tutorials are pretty good (and free for the first few)
Good HTML reference pages
due, Sat. night 2/2 midnight.
Find and evaluate at least one good HTML reference site and/or tutorial site.  Provide the URL(s) and your review.  On the other hand, if a site is not very good, say so.  Put your comments into the Comments-to-Teacher section.

Here are the Sites you found, with commentary:
Period 3
Period 4
Period 5
First task: fill out your Profile on the Homework server.
  1. Go to the main class link page (http://bert.stuy.edu/pbrooks)
  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 OSIS number as your password
  6. Fill out your email address 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 from Mr. Brooks Feel free to come and see me during periods 6, 7, or 8 in room 301 (just walk in) or by appointment beforehand just after school also in room 301.
Sending email to Mr. Brooks:
Send mail to: pbrooks@stuy.edu

You MUST include your name in the subject line or body of the message, otherwise I won't know who it's from.
Stuyvesant bell schedule  
Homework/grade server  
Support Wikipedia