Intro to Comp. Sci  (year) - 2

Spring 2021 -- Peter Brooks

Some Python documentation...

.split() and .join()

CSV exercises, due: Thurs 4/15 (pds 3,4)
Fri, 4/16 (pds 9,10)

.split() and .join are very useful string methods.  Here's how they work.

A lot of data comes in .CSV format (Comma-Separated Values).  Here's a first set of exercises that asks you to process such data...

.split() exercises.
Ah, lists...

Homework due: Tue, 4/13 (pds 3,4)
Wed, 4/14 (pds 9,10)
Once you know about strings, indexing and slicing, lists are an easy extension.

List homework #1
Even more on strings...
  • We take a look at the special character for a new line -- the character corresponding to the Enter key: "\n"
  • Removing leading and trailing "white space" with .strip(): 
    "  fred  ".strip() -> 'fred'
  • The Really useful method: .replace(): 
    "I love the theater".replace("the","my") -> 'I love my myater.'
  • Asking questions and getting answers with the input() function:
    name = input("Enter your name, please: ")
Strings, strings, more strings
Due Wed 4/7  (pd 2,3),
Thurs (pd 9, 10)
We take a look at string methods, like .upper() and .find() and can use them for string transformations, like encryption.
Do the following string exercises, which will be due after the break.

Here are my answers.
Letter coding
Due on CodingBat
Wed 3/24 (pds 3,4),
Thurs 3/25 (pds 9,10)
ASCII codes and Unicodes are ways of storing characters as numbers.  You can find the code for a letter (e.g. for ASCII code for "A" is 65) using
ord("A") -> 65
, and in reverse,
chr(65) -> "A"
You can then "shift" each upper-case character in a word forward by one (e.g. "A" -> "B", and "B" -> "C", ... "Z" -> "A") with
def ShiftUppercase(c):
  if c == "Z":
    return "A"
  return chr(ord(c) + 1)

Do the CodingBat exercises:
shiftCharacterByOne,  shiftCharacter,  shiftWordByOne,  shiftWord
Using for and range() for looping.

Python #3 homework due
3/22 8:00a for pds 3,4
3/23 8:00a for pds 9,10
Here are examples of the use of for and range() to create loops.  Also, here is the use of break to terminate a loop prematurely.

In a belated celebration of Pi day (yes, we missed it... why didn't y'all say something ... huh?), we'll have Pi calculations.  Yes!
Here are a couple of exercises, plus optional (if you really like math) problems having to do with Pi.

My answers are here.
Strings, and more strings.
Homework due before next meeting (Thurs or Fri, 3/18,19)
  • For quick documentation on strings, look at the Python cribsheet, second page, top right, for examples of string slicing.
  • Here are several of the CodingBat functions with answers, to serve as examples (e.g. findLetter(), isVowel(), and others) of how to manipulate strings.
  • For classwork and homework, do the following problems in CodingBat -- be sure to log into CodingBat (otherwise there's no record of your work).  Just do the exercise inside CodingBat -- no need to upload to the homework server.
  1. countLetter
  2. countVowels
  3. isConsonant
  4. countWord
  5. noVowels

Here are my answers....

We're starting to work with CodingBat

CodingBat (with Mr. Konstantinovich's additions) is a site with Python (and Java) problems, and has an online tester.
Follow these intructions carefully to register with CodingBat
In class (or afterwards) do the following problems (if at home, make sure you're logged in to the site): 

  • sleep_in
  • monkey_trouble
  • near_hundred
  •  diff21
  • lone_sum
Python homework #2:
Due (periods 3,4): Wed 8:00
(periods 9,10): Thurs 8:00
Homework is here.

Answers are here.  Remember that there are many ways to solve these problems correctly, and my answers are not unique, nor necessarily the best.
Personal homepages are up!
Voting due by Thurs night, 3/11

Vote for the 2 best homepages on the form HERE... 

First of all, most of these webpages, competitive and non-, were an enormous amount of work (yes, I know).  And the outpouring of sheer creativity never fails to make me proud of the students in this course.  A quiet thank-you to you all.

  • You must look at every competitive webpage in our class.
  • You ought to look at the non-competitive ones as well. 
  • Admire your own.
  • Don't just look at the styling...
  • ... read the words, pause, think of the person behind the page, think of what impresses you about this creation.

The Big Nos:  No you can't vote for yourself; No, you can't vote for the same person twice; No, you can't vote for someone in another class; No, you can't sell your vote (or barter).

1st prize is 2 extra points on final course grade (except over 100); 2nd prize: 1 extra point.

First Python homework
Due (periods 3,4): Mon 8:00
(periods 9,10) Tue 8:00
Download this file (python-demo-1.txt), then change its suffix from ".txt" to ".py" and then load it into Thonny
Python exercises #1
Answers are Here.
Python!  Thonny!
For Tues/Wed, 3/2,3/3 classtime
Download, install, and run Thonny, our preferred Python development environment (although you can use others).
Privacy, security and passwords

Files/Directories,  directory trees
  • A wonderful, but mathematically challenging XKCD on password-design for those of you who want to store them in human memory.
  • Here are a group of password managers with short reviews
  • Using the tree command
Wed/Thurs, 2/24-25: Imitate this page task In your breakout rooms, collectively figure out how to imitate this page. Here are the notes/suggestions for doing so, and here's the good ol' duckCat.jpg.

Here's the actual webpage, so that you can View-Source and see the HTML and CSS I used to create it.
Homework #3, Your personal homepage:  to be finished by Sun 2/28 night. Create a webpage or set of webpages about yourself. 
You can talk about /show your interests, hobbies, sports, music, etc.
This will be published on one of our CS dept. servers.

Rules: you may NOT use a web-authoring program (like DreamWeaver) -- just a text-editor.
You must write all of your own HTML and CSS code.  --  you may not use packaged javascript or css files/libraries.

Put the URL of your page (e.g. here's a simple one about Mr. Brooks's books into the Comments-to-Teacher, along with a sentence or two about your experience in creating it.

Also, add whether you want to enter it into the class competition .  If you say nothing, you won't be entered, but your URL will still be posted on the competition page (just like in the Shape/locomotion competition).
Daily Double Digital The Daily Double Digital is a 4-minute presentation on any digital topic that would be of interest to the class.  Be prepared for a couple of minutes of questions.
There will be 2 presentations at the beginning of each class period.

The Schedule is here
It is your responsibility to know when you're up.  If you need to cancel, provide me the reason for it at least a day in advance, otherwise it's a no-show.
Connecting to our CS server You'll be connecting to the computer: 
You can use one of several free File Transfer Programs:  FileZilla  (Windows, Mac & Linux),  or WinSCP (Windows only)

In FileZilla, the settings are:
username:  your user name, like hpotter30
password: your password
port: 22

HTML/CSS References and Resources Here are the great resources that y'all found out there.  These will be useful for constructing your personal homepage(s).
Period 3's finds
Period 4's finds
Period 9's finds
Periods 10's finds
Homework #2, due:
Wed 2/10 8:00 for periods 3,4
Thurs 2/11 8:00 for periods 9,10
Create a document like this for all of the HTML (and any CSS) codes that we have covered.  Save that document in .PDF format and submit to the homework server.  I'd gently recommend changing my name to yours.
Homework #1, due 8:00a before next class Check out the W3Schools site -- learn to use it.
Find and report on a good source of HTML and CSS information other than W3Schools, that's perhaps easier to work with, or has some other advantage.  Post its URL in the Comments-to-Teacher, and say why it's better in some way.
For Mac users of TextEdit: TextEdit is the built-in editor for plain text files, but it defaults to rendering html, rather than displaying it.  You can set its preferences to support editing html:
In the menu TextEdit > Preferences, on the New Document tab
  • select Plain text
On the Open & Save tab,
  • set Display HTML files as HTML
  • clear (un-set) Add ".txt" extension to plain text files
First task: fill out your Profile on the Homework server.
  1. Go to the main class link page (
  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 to the class channel: #office-hours during office hours or make an appointment with me by email.

Office Hours Zoom (sometimes) -- preferably, send me email beforehand if you will want to Zoom-talk...  I will also be on the channel: office-hours 
Meeting ID: 811 5113 1539
Passcode: 235232
Sending email to Mr. Brooks:
Send mail to:

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