CS - Intro - Pilot

Intro. to Comp. Sci (year) - 2

Spring 2022 -- Peter Brooks & Janet Vorobyeva

Challenge Problems (for if done in class).
Python Reference Sheet.


Final Project Gallery! Your projects are graded, and I've put up a gallery of links for you to peruse your classmates' work.

Link to final project gallery
Final Project: Pokedex

Phase 1 Due Mon 06/06 at 8:00am

Final Version Due Fri 06/10 at midnight

+3 Points if finished by Wed 06/08 at 8:00am
Link to project instructions

Reminder, for the final submission, you must have:
  • In the normal file slot: your .py file that generates your site
  • In comments-to-teacher: The URL of your site (on homer.stuy.edu/...)
  • In comments-to-teacher: any bonuses you've added to your site
Make sure that the URL you put in comments-to-teacher works correctly, e.g. works from someone else's computer or from your phone.
HW19: Dictionaries

due Fri. 06/03 at 8:00am
Here are some notes on dictionaries

Dictionaries HW

Here are my answers

Notes/Hints:

General hints: you'll be using a dictionary to count occurences of various things.
  • Make a small list of numbers / small string of chars to test your functions on first
  • While testing, print() out your dictionary each loop to make sure you can see what's going on
  • When you're done counting occurrences, you'll need sort by most/least frequent, but dictionaries don't have a notion of order. To be able to sort something, write some code to construct a list like so: [ [val1, key1] , [val2, key2], ...] You will need to loop over all the keys in the dictionary to construct this list.


In problem 1: the f.readline() is just a slightly different way to loop over the lines in the file. Don't worry about it, that code is equivalent to this:
        f = open(filename,'r')
        lines = f.read().strip().split("\n")
        for line in lines:
            if line.isdigit():  # make sure it's an integer string (e.g. "123")
                #do some stuff
        


In problem 2: you can use char = char.upper() to change case. You can use ord(char) <= 127 to check if it's a valid character;
HW18: Multipage HTML

addition due Thu 06/02 at 8:00am due Wed 06/01 at 8:00am
=== ADDITION WED 06/01 ===
    ADD THE FOLLOWING TO YOUR SITE:

    - Download this zip file, which contains 10 images of numbers.
    - Unzip that, put the 'numbers' folder inside your hw18 folder
    - Modify your script to include an image of the appropriate number on each page
    - Modify your script to also generate an index.html file
        - index.html should have a link to each of the pages
        - each page should have a link back to index


    Bonus:
    - here's a way to add simple navbars to your site: Navbars
    - Add a navbar to the top of each page, containing a link to the index, and a dropdown
      of links to each individual page
        

=== END OF ADDITION ===


Homework 18: Using python to generate multi-page sites

Here's a guide on transferring webpages to your public_html directory on homer.
HW17: Real Data Analysis

due Tue. 05/31 at 8:00am
NOTE: solutions to HW16 are now up. While I am out today, please work on the following assignment. Note if your classmates are unaware of this assignment, please let them know that there is work up on the homepage.
Today you will be working with a real dataset of SAT scores from NYC schools in 2012:
  1. First: if you were having trouble with HW16, take a look at my posted solution, and make sure you can get your version working.
  2. Download this csv: 2012_SAT_Results50.csv. This is a subset of this dataset from NYC OpenData, limited to the 50 schools with the most SAT test takers.
  3. Write a function to read in this csv file, split it, and convert the number columns to integers, and return a list of lists.
  4. Write a function that takes this data (as a list of lists), and returns the row (i.e., a list of len 6) with the most SAT Test Takers
  5. Write a function that takes this data (as a list of lists), and returns the row with the highest combined SAT Score.
  6. Write a function that takes this data (as a list of lists), and returns a list of [ average reading score, average math score, average writing score ]
  7. Putting it all together: Your program, when run, should read in the csv file, process it, and write out an html file with the following:
    • Full html structure (html, head, title, body)
    • An html heading at the top of the page (e.g. h1)
    • Some text describing, what this dataset is, and where it came from.
    • An unordered list of the school with the most test takers, school with the highest score, and a listing of the averages for the scores.
    • A full table of all the SAT results, with the column names

Bonus: If you're done try adding the following features:
  • Bold and underline the column names
  • Sort the table by either name, total test takers, or score
  • Add an extra column to the table for "Combined SAT Score"
  • If you finish all the bonuses, see if any of your classmates are stuck or want help

Submit your .py file to the homework server as per usual.
Python HW 16: HTML Revisited

due Fri. 05/27 at 8:00am
Homework 16: Using python to generate HTML from CSV data.

Remember you can use the string.strip() method to remove trailing whitespace. A common pattern is to read file data as fileLines = file.read().strip().split("\n")

Also, for generating string output, you may find it useful to use the methods string.join(...) and string.format(). Here are my solutions
Python HW 15: Accounting Software

due Thu 05/26 at 8:00am
Notes and examples for working with CSV files

Here's a name and wage file. With each person's name there is listed their: pay per day, their start date at work, and their last date of work.

Save this file in the same directory as your .py file. Write a program to read in the file and answer the following questions. Put your answers in the comments-to-teacher box. Also upload your .py file as usual.
  1. Who earned the most total pay during their time on this job?
  2. Which 3 people worked the fewest days? How many days did they work?
  3. What was the average amount each person earned? (i.e. average of the total-pay)

For testing your code, I recommend writing some test cases against a smaller dataset, like this one.
File reading classwork Download the following file: reverse_me.txt (open it, right click, "Save Page As")
Save the file in the same directory as your .py file, otherwise python will not be able to open it.

  1. In python, write code to read in the file and print out its lines in reverse order (i.e. last line goes first)

  2. Then write code to output the lines (in reverse order) to a new file. You should be able to open the output file in a text editor and verify that it has the correct contents.
Lab: .split() Exercises

due Wed. 05/25 at 8:00am
Today's Lab Assigment: More .split() exercises

For this assignment, in addition submitting your .py file, please also put your answers to each question in comments-to-teacher.

As usual, mention who you worked with, how long it took, and whether all the test cases worked.

Answers:

  1. 100 Names
  2. Longest first name: 10 characters, "ALEXANDRIA"
  3. Longest last name: 13 characters, "KROP-SIEGMUND"
  4. Mean score: 10.88
  5. Top 3: SAYAN GRAEBER 20; AFIA HUMAIDEE 19; XINQING LEUNG 18
Python HW 13: Numeric Analysis

due Mon. 05/23 at 8:00am
due Fri. 05/20 at 8:00am
=== ADDITION FRI 05/20 ===
  • If you were not able to get steps 1-3 working last night, take a look at the partial solution posted now. Make sure you understand it, and use it to go fix your code. DO NOT just copy-paste it, copy pasting will not reduce your confusion, but rewriting it will! After you get steps 1-3 working, then work on calculating the median.
  • If you were able to get steps 1-3 working last night, but not the median, then for homework, get the median working, and resubmit
  • If you got all parts of the homework working last night, then congratulations, and enjoy your well-earned rest.

=== END OF ADDITION ===

Homework 13 Problems: Working with numbers and extracting summary statistics.

NOTE: this is a function with many parts. Make sure you go through it one step at a time, as detailed in the assignment. Do the median last, if you can't get the median working in a reasonable timeframe, you should at least make sure you get all the other parts working.

As usual, mention who you worked with, how long it took, and whether all the test cases worked.

Here are my solutions (now with median!)
Python HW 12: List Mutation

due Thu. 05/19 at 8:00am
Here's a lists reference sheet that you may find useful.

Homework 12 Problems: Modifying lists and list aliasing.

As usual, when you submit your .py file, please mention who you worked with on it (if anyone), how long it took you, and whether all of / which of the test cases worked.

Here are my solutions
Python HW 11:
String Methods and Documentation

due Thu 05/11 at 8:00am
Here is a link to the Python Standard Library Documentation. For today, you'll be looking at the section Text Sequence Type - str under Built-in Types.

For homework: read through the documentation for str.upper(), str.replace() For each of these, come up with test cases like the following:
print('"apple".replace("p","ba") should be "ababale", is: ',  "apple".replace("p","ba"))
Make sure you write down what you expect the output to be BEFORE running your test case; this will force you to make a mental model of what the function does, which is helpful to undestanding.
Write at least two test cases for each string method.
  • Then, skim (i.e., no more than 5 minutes total) through all of the string methods in Text Sequence Type - str. Not all of them are useful to you, and some use techniques we haven't discussed yet, but many will be useful and interesting.
  • Pick two string methods that seem interesting or useful. Read through their descriptions, try to predict what they do.
  • Write at least two test cases for each of the string methods you chose.
Please submit this as a .py file. As always, please put how much time you took, in decimal hours, in the comments-to-teacher.
Python HW 10
due Wed 05/04 at 8:00am
Homework 10 Problems: Character shifting and ciphers

Update on homework submission policy: when you submit your homework, make sure you also add the following to the comments-to-teacher box:
  • How long it took you
  • Who you worked with, if anyone
  • One of the following:
    • "It worked on all of the test cases listed with the homework"
    • "I wasn't able to get the following test cases correct:" [and then list them]
    • "I wasn't able to get the following function working at all:" [and then explain what you were able to get working]
Python HW 09
due Tue 05/03 at 8:00am
Homework 9 Problems.
Python HW 08
due Fri 04/29 at 8:00am
Homework 8 Problems, now with explanations.

Here are my solutions
Python HW 07
due Wed 04/27 at 8:00am
NOTE to PD5: I ended up removing findWord from the hw and replacing it with 2 easier problems

Tonight please finish the Homework 7 Problems. In comments: how long it took at home, who you worked with in class.

Here are my solutions
Also, solutions to the "bookkeeper" problem from a few days ago
Python HW 06

due Tue 04/26 at 8:00am
UPDATE 04/14: Solutions to HW04 and HW05 are now posted below.

Homework 6 Problems.

Problems related to string indexing, will be due after we get back from spring break.
In comments: how long it took at home, who you worked with in class.

Here are my solutions
Python HW 05

due Wed 04/13 at 8:00am
Homework 5 Problems.

Here's some problems related to strings. Once you're done, submit your .py file to the homework server. In the "comments-to teacher" box, put how long the hw took you to do (in decimal hours).

Here are my solutions
Python HW 04

due Sun 04/10 at midnight
Homework 4 Problems.

Here's some problems related to the hailstone sequence / collatz conjecture that we looked at in class today. Once you're done, submit your .py file to the homework server. In the "comments-to teacher" box, put your answer to question 4, as well as how long the hw took you to do (in decimal hours).

Here are my solutions
Python HW 03

due Fri 04/08 at 8:00am
Homework 3 Problems.

Work through these to figure out what they do. Once you're done, submit to the homework server in "comments-to teacher" how long it took you to do in decimal hours, and whether the output was as you expected or not.
Quiz Review:

will be on Thu. 4/7
Quiz will be on Thursday, 4/7. Will be roughly 20 minutes long.

You are allowed a one-sided sheet of notes, no bigger than standard computer paper, which will be collected at the end of the quiz.

Some topics to review (in no particular order):
  • You should review for i in range(...):
  • You should be able to run through the execution of a while loop and write out the loop table (i.e., values of variables at start of each iteration, whether the loop test passes or fails, what changes in the body).
  • You should be familiar with the math operations (+ - * / %), and the comparisons (==, <, >, <=, >=, !=), and the logical operations (and, or not).
  • You should be able to determine which path the code will take through a series of if ... : and else: statements
Python HW 03

due Tue 4/05 at 11:59pm
Consider the following code:
    def foo(n):
        print("x")
        return(n * 10)
        print("y")
    print("a")
    i = 50
    while i < 1000:
        i = foo(i)
    print("b")
    print(i)
    
    
ON PAPER, WITHOUT using a computer: write down what you think this code will print. It may help you to keep track of variable values as you go.
When you're done, check your answer with thonny: go through your own answer and figure out where it differs from the actual output and why.

You don't need to submit anything for this, but you should work through it. We will be having a small quiz on thursday and this will be helpful for it.
Python HW 02

due Sun 4/03 at 11:59pm
Please complete the 2nd Python homework. Submit your .py file to the homework server.
  • In the "comments-to-teacher box", please write how much time you spent working at home on this homework, in decimal hours. (i.e. if you spent half an hour on it, put 0.5).
  • If you worked with someone on this homework, write it in the comments-to-teacher box.
Python HW 01

due Wed 3/30 at 8:00am
Please complete the 1st Python homework. Submit your .py file to the homework server.
  • In the "comments-to-teacher box", please write how much time you spent working at home on this homework, in decimal hours. (i.e. if you spent half an hour on it, put 0.5).
  • If you worked with someone on this homework, got help from someone, or helped someone on their own homework, you must mention that in the comments-to-teacher box. I strongly encourage collaborating with your peers, as working together and dicussing code can be very helpful, but make sure that you attribute your collaborators.
Challenge Problems If you're done in class, try working on some of these problems.
Notes for Tue 3/22

due Thu 3/24.
Please do the following codingBat exercises.
  • isBig
  • sleep_in
  • monkey_trouble
Try to solve these using just if and else.

Try to solve these WITHOUT using and, or, not, (which we haven't gone over class). Also for monkey_trouble, try solving it without doing a_smile == b_smile. Both of these would be a cleaner way to do it, but I would like you to try working with nested ifs, as that will hopefully be more helpful to you going forward.

Some notes on if statements:
# Assuming we have a numeric variable x
if x > 10:  
    return 1 # If test is True (above 10)
else:
    return 2 # If test is False (not above 10)


#Comparison operators:
# Less/greater than: >, <
# Less/greater than or equal to: >=, <=
# Equal/not equal: ==, !=
# NOTE: a single equal '=' DOES NOT CHECK EQUALITY.
#       a single equal '=' assigns values to variables


# Note: if we have variables a and b that hold
# either True or False, we can test them directly without a comparison
if a:
    if b:
        print("Both a and b are True")
    else:
        print("a is True, and not b")
    print("a is True")
print("prints always")


# True and False are values in python like 0 and 1
# Don't quote them: "True" is a string, (not what you want here)
if a: 
    return False
        
Work 1: CodingBat

due Mon. 03/21 at midnight
CodingBat is a site with Python (and Java) problems (as well as some additional ones written by Mr. Konstantinovich). It lets you write and test your code online, and we will be making use of it throughout the semester.

You should go to https://codingbat.com/home/konstans@stuy.edu/all and register for an account.
One-time registration:
  1. Create an account using your email address and make up some pasword that you'll remember
  2. After logging in, click on the "prefs" link (on the upper-right of the window)
  3. In the "Teacher Share" field, enter jvorob@stuy.edu and press the Share button
  4. In the "Memo" field, enter 2022,your period,lastname,firstname with no spaces.
    For instance: 2022,9,Shelley,Mary 
    and then press the Update Memo button.
Once you're registered, do the following problems (make sure you're logged in):
  • square
  • evalQuadratic
Work 0: Thonny

Do tonight, Thu 3/17.
Nothing to submit
Download Thonny onto your personal computer. Write a hello world program: print("hello world"), and run it (Run > Run current script)
            
Personal Homepages are up!

Voting homework due Sun midnight.

I will be out the rest of this week (March 10th - 11th). Please use your class time to look at, discuss, and vote on your webpages.

Voting rules:

  • Look at ALL of the pages for your class.
  • You'll be posting your votes to the Comments-to-Teacher
  • Provide 2 votes, for 1st and 2nd place (must be for 2 distinct students)
  • Vote only for students in your class and in the competitive category
  • You may vote for yourself, but not more than once, unless you have a split-personality (but then each will be given only a half grade)
HW: Internet Oddities

Homework due Fri 3/4 8AM
(i.e. before class tomorrow)
Come up with one way you've interacted with the internet that is not primarily loading a webpage. Alternatively, think of a situation where the internet seems to be doing something weird that can't be explained by the things we've been discussing in class. (e.g. like when you try to connect to the wifi at starbucks and it redirects your usual sites to a starbucks-specific wifi page)

Please write a few words or sentences describing your thing, and submit to the hw server in the comments-to-teacher box.
Help from Ms. Vorobyeva I can be found in the CS office (room 301). The best times to find me there are 6th period or after 10th. If you're willing to try your luck, I'll usually be free 8th period as well. Please come by anytime if you have questions.
Sending Email to Ms. Vorobyeva:
send mail to: jvorob@stuy.edu

Please include your name and class period in the subject line of your email.
Ms. Vorobyeva (a.k.a. Ms. V) Taking over from Mr. Brooks as of Wednesday, 3/2.
The Internet and how it works Here's a video about how a webpage requested by someone in England but located on a computer in Los Angeles gets to him.
Personal homepages graded task.
Due Mon, 2/28, midnight.
  • Create a webpage (or webpages) about yourself, or your interests.  Use this opportunity to show off your webpage design skills as well as your creativity on content.
  • This page will be seen by all of your classmates (actually by all 3 IntroCS classes I teach).
  • Use good and pleasing design (or harsh design if that's the mood you want to create)
  • You must type and understand any HTML or CSS (or Javascript) code you find on the net and want to use.  Feel free to steal (though you must do the typing) and learn (you cannot add anything you don't understand).
  • You MAY NOT use any "frameworks" like Bootstrap or React, etc.  You MAY NOT import code using the <link> command, but you may use it to import fonts.
  • You MUST use an ordinary text editor (like TextEdit, Gedit, NotePage, NotePad++, or other) wherein you type the actual HTML and CSS code yourself.
  • Upload your page and any image files to your public_html directory on homer, and create and test the URL you'll be giving me and everyone else to view your page(s)
  • TEST your URL!  Remember, it will be something like:  http://homer.stuy.edu/~your-id/your-html-file.html.
  • For the homework server:, write your URL into the Comments-to-Teacher, and also add whether you want to enter your page(s) into the class competition.  If you don't tell me, I'll automatically assume that you do want to enter the competition.
  • Sometime after the deadline for submission, y'all will be voting on which you consider the best webpages.  Everyone will see every webpage from their class and will vote.
  • I will also grade the pages on effort, creativity, design and content.
Friday: surprise quiz. Shouldn't be too hard. You're responsible for all of the HTML we've covered, and the CSS material covered in the first 5 tutorials videos below.
CSS tutorials online... - Here is the start of a sequence of short video tutorials on CSS: Watch at least the first 5 videos in the sequence.  These are really good and very short, and the rest of them -- the ones on "classes" (videos 6 and 7) and the ones on fonts (8 and 9) as also good.  Watch these, I recommend them.

- The videos assume that you're familiar with the HTML commands <h1> (a header type) and <p>  (a paragraph), which we'll cover in class.
- I will also cover <title> and how to access picture files that are in a different directory than your HTML file.

- I will assume that you've seen the first 5 for CSS material that might be on Friday's quiz.
CSS and Javascript. A little bit about CSS and Javascript...
Homework for Valentine's Day night (Mon, 2/14)
  • Let's learn to publish our webpages....
  • Here's a guide on transferring our webpages to our public_html directories on homer.
  • Create a small webpage ON YOUR HOME COMPUTER about something you're passionate about (or deeply interested in, or mildly enjoy, or just tolerate). 
  • Publish it by uploading it, along with any pictures of your own that it uses, to your public_html directory on homer.  You MUST copy these files from your home computer to homer -- you cannot just create these files on the student computers at school and copy them to your public_html directory.  The main purpose of this homework is to practice transferring.
  • Write the URL of that webpage into the Comments-to-Teacher, so I can look at it, and also write any comments about difficulties you had.
Classwork for Thurs, 2/10 Work on creating a webpage that looks like this: CopyThis.jpg
You can have your own text, but the layout and visual effects should be the same.
I want to see this on your computers in class on Friday.
Finding and using good HTML References and websites to learn from...

Homework, due Wed. 2/9 midnight
  1. Check out the W3Schools site.  Learn how to use it.
  2. 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 a built-in editor for plain text files, but it defaults to rendering HTML (like a browser), rather than display it (like what you typed). 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 as HTML
  • clear (unset) Add ".txt" extension to plain text files
Thurs, Fri -- I'm out with a cold. Next week we'll start on HTML.  After that, there'll be no stopping us.
Use today to relax, it may never happen again.
Wed, 2/2: for Periods 9 & 10:  I'm out today, but expect to be back tomorrow. - The entire class task is to register with the new Homework server (set up your Profile, just like you did at the beginning of last semester) and test your new password. 
- Instructions below.
- Please help those students who didn't have me last semester.
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 (or use the one at the bottom of this webpage)
  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: (press Change Profile button)...
  8. (optional, but recommended): now you should change your password for this Homework server:
  9.  Go back to the Profile page, create a password and press the Change Password button.
  10. REMEMBER this password!
Help from Mr. Brooks In school, I live in the CS nest (room 301). I'm free periods 6,7,8.  Come on in, no appointment necessary.  If I'm busy, we'll work out a time.  If I'm not there, ask someone when I'll be back and/or try reaching me telepathically.
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  
Mr. Brooks MicroMind, Inc.
Support Wikipedia