header image
Check this page for updates on upcoming classes, our learning goals, and the lesson modules we'll use to get there.

Session Calendar and session guides

CIT-129: Python 2

Weekly guides

Guiding questions, objectives, and lesson activities are available for each week of class. Click "toggle full session guide" to view the full guide.

Wk 1: TUE 4 SEP - MON 10 SEP

Reviewing the essential built-in types in Python

live_helpGuiding questions

  • How do Python's built-in type set compare to other languages you know?
  • What are the definining features of tuples, lists, and dictionaries?

check_circleLearning Objectives

  • Create and manipulate small quantities of data in tuples, lists, and dictionaries
  • Process Strings with slicing and built-in methods on String objects
  • Creatively engineer a program for storing and displaying information about our classmates


listBuilt-in types opening activity

The Python types that we'll review tonight:

  1. Numbers
  2. Strings
  3. Lists
  4. Tuples
  5. Dictionaries

The challenge specification:

  1. Design a dictionary whose keys describe what values you'd like to learn about your peers in this class. Design the dictionary on paper, specifying the data type of the value. You must store at least one of each of our review types.
  2. Once the specification is done, pass the dictionary design to a peer, and ask them to populate the dictionary values with appropriate syntax.
  3. Now, at a computer, create a simple program which creates this dictionary, whose keys are all strings, and hard-code the values from yet a third person's dictionary.
  4. Create a simple mechanism for retrieving the value of one of the keys in the dictionary using user input.
  5. Prepare to demonstrate your program to your peers.

listString slicing exercise

  1. Write a short program that reads in a String and prints out the first two followed by the last two letters of this string only. Before performing this operation, check to make sure the user entered a String of at least 4 letters. If it's too short, reject the input and end the program.
  2. Write a program that checks to see if the second and second-to-last letter of an inputted string are the same letter. If so, print a corresponding message to the user. If not, terminate with an ominous message.
  3. Ask the user for three strings. Input these into three different String variables. Once you have the data, print out these three strings on one line, organized from the shortest to the longest words. If words are the same length, the order is irrelevant.

listLooping review exercise

This exercise is intended to provide a review of basic looping and listing facilities in Python. If this exercise is a challenge, that's okay--it's a check-in exercise!


  1. Envision on paper using pseudocode a program which asks the user for an integer. The program then should display the a list that counts from 0 up to this given integer. Finally, the program should display the total of each of the elements of this list added together.
  2. Code the program in Python and test it
  3. Study the sample output for help

Sample program interaction

python output


  • If these exercises were challenging, please make sure you come next week with attempted code for each and questions you have to complete the exercises.
  • Create a custom data type using nested dictionaries that stores information about a topic of your choosing that you find interesting. Prepare a hard-coded sample of a datum using this particular dictionary scheme.

cakeExtension exercises

Revisit with gusto the differences between the various python Built-in types.

arrow_upwardback to schedule

Tuesday, 11 September 2018

Looping and methods

live_helpGuiding questions

  • What makes Python looping and iterating more convenient than in Java?

check_circleLearning Objectives

  • Use a for-loop to iterate over various data structures
  • Create dictionary-formatted strings

arrow_upwardback to schedule

Tuesday, 18 September 2018

File I/O

live_helpGuiding questions

  • How does Python interact with the operating system to navigate the file trees?

check_circleLearning Objectives

  • Harness python's file interace to read, write, and process data in files


listLesson sequence

  1. Build a shared understanding of our file I/O tools on the white board using our linked resources

Exercise 1: Looping to a file

Study the following file contents. Generate a program in Python to reproduce this structure. NOTE: You'll need to use two for() loops, nested. You can try seeing if you can print the pattern out first to the console, then replace the calls to print() with calles to yourfile.write().

file example

Exercise 2: String formatting program specification

  1. Download the following text file of names: file link
  2. Your desired program output is a formal greeting for individuals whose names exist in a text file in the order: first last. The output should look like this:
  3. output
  4. The process of generating these greetings should take place in two methods: one should read in a file given a file name (assumed to be in the working directory) and extract the name in a single line. The second method should receive a line of text (i.e. a name in the form first last) and generate the greeting. Remember, you'll need to invert the string since we're using string formatting, not string concatenation.

playlist_add_checkMid-week ToDOs

Jail population statistics calculation example: recreate this program without using the CSV module at all! You'll need to use the split() function to break down lines of text from the file, and you'll want to use zip() to combine each row after the header with the values in the header row.


A program that conforms to the mid-week TODO specificaiton

arrow_upwardback to schedule

Tuesday, 25 September 2018

Data encoding: JSON and XML

live_helpGuiding questions

  • What are the most widely used protocols for exchanging data between systems?

check_circleLearning Objectives

  • Parse JSON files into Python objects and manipulate those objects
  • Create JSON files from Python objects and transfer that data to other python systems


listLesson sequence

  1. Course oranization system: gitHub and upload index, folders, attendance
  2. Review work from last week: programming CSV parsers without CSV module
  3. JSON, XML, and serial binary format notes
  4. JSON parsing simple examples: opening and printing the Capital projects in PGH
  5. Mini task 1: Use a for loop to list all project info in a neatly formed set, like shown in the screen shot below:
  6. Mini task 2: Write a method called logMalformedProject that is called each time a project is visited by the main loop that does not contain a value for the key 'area'. This method should write the project id to a single line in a log file with an appropriate name.
  7. Mini task 3: Create a method that assembles a list of unique values for the project area. If you are feeling ambitious, do the same for 'status' and 'asset type' since this will come in handy during the search specification.

Screen shot of capital project print formatting

capital project analysis output

playlist_add_checkMid-week ToDOs

Start thinking about an API and an API key

An API key is a unique identifier that a coder provides to a remote server which unlocks the release of data to the requetsing client. Each server with an Application Programming Interface configures its data restrictions differently, but many require an API key to be sent with each request.

Visit programmableweb.com for a directory listing of thousands of servers with some form of API. Browse some that look interesting, click into that data source's profile, and make sure that the data is free and that the server returns JSON-encoded data.

Keep developing our class project

Write python code that conforms to the following specs:


Implement search criteria defined in the JSON format for searching for capital projects in PGH dataset, outputting resulting projects into a file in JSON format

program requirement 1: searching

Write code that can read in a search criterion JSON file of your specification. You'll need to be prepared to share this specification with others in the class

Allow the user to specify search criteria for project fiscal year, start date, area, asset_type, and planning status

program requirement 2: management costs

Write a method that will calculate total project management costs for all the capital projects in Pittsburgh given a management cost scheme, encoded in JSON as specified by the class. Example: For all projects up to $10k, management costs are 8% of the total project budget. For projects between $10k and $100k, management costs drop to 5%, and over $100k, costs increase to 11%.


  1. Working code from mini-tasks 1,2, and 3
  2. A solid attempt at the full project specs in the green box
  3. A possible API source for the week after next

cakeExtension exercises

We can turn python objects into JSON files easily that can be digested by servers all over the world. We can also turn python objects into files that can only be eaten by other python interpreters. The library for this is called pickle. Try serializing (turning a python object into data inside a file, instead of in RAM) your project objects and resurrecting them using the pickle library.

arrow_upwardback to schedule

Tuesday, 2 October 2018

HTTP, Requests, and screen scraping

check_circleLearning Objectives

  • Explain the essential structure of HTML pages and how they store structured information. Write a basic HTML page about a life interest.
  • Employ the urllib and BeautifulSoup libraries to pull down an HTML page and find a particular element, and extract the data in that element.
  • Systematically store the result of a screen scraping endeavor into a text file that can be shared and used as inputs by other programs or tools.


listLesson Sequence

  1. Structure of the WWW: Requests and responses in browsers
  2. Using request and response libraries in URL lib
  3. Structuring documents in trees! HTML basics
  4. Using Beautiful soup to parse a simple HTML File
  5. Run through screen scraping example on GoodReads.com. Learn how to use urllib and BeautifulSoup
  6. Work time on screen scraping project

cakeProducts to Produce

  • Code to the specification below. Then upload your a python files and any related documents to your GitHub account. I suggest creating a subdirectory in your git repository called "scraping" or something like that.

program objective

Create a program that uses the urllib and BeautifulSoup to grab HTML code from a public source, parses that source into meaningful bits of data, and spits those meaningufl bits of data into some form that could be transfered into anothre tool, such as a CSV for slurping up into a Database, a JSON file for use in the web, etc.

suggestions for good pages to parse

Choose a website whose page content is retrieved with some sort of query, such as a URL-encoded search query. This will allow your system to programatically tinker with the results you get back, and can be scaled to process lots more data than just a single, static page.

Pages with tables of data are great, since that allows us to loop over trees of page elements and procss their data one at a time

use methods!

When possible, please structure your code in discrete methods that accomplish a single task, returning useful values to the caller. This helps reduce code repetition, allows for modular re-use, and makes the code generally more readable than blobs of lines in a heap.

arrow_upwardback to schedule

Tuesday, 9 October

Special project in file/os tree visualization

live_helpGuiding questions

  • How can we help early computer learners visualize and interact with file trees?
  • What tools are embedded in the OS package that can help us with visualizing file trees

check_circleLearning Objectives

  • Harness critical methods of the os module


listLesson sequence

  1. Discuss high level goals of the program and explore sample file trees
  2. Practice traversing the directory structure tree in Python
  3. Design specs for individual components of the project

playlist_add_checkMid-week ToDOs

We want to prepare for our API endeavor next week by doing the following steps:

Please create a program that calls an API of your choosing from the online index of available APIs called ProgrammableWeb.com. Use our sample code on GitHub and from last class to create a program that calls one of these APIs, retrieves a JSON file from the server, and parses that JSON file to produce some kind of output that is useful. Remember, this can be very simple: create an average of some quantitative measurement returned, etc.

Sample code for an API call to donorschoose.org.

arrow_upwardback to schedule

Tuesday, 16 Oct 2018

Application Programming Interfaces

live_helpGuiding questions

  • How can we leverage the power of a remote database system programatically in python?

check_circleLearning Objectives

  • Use the requests library and supporting modules to request information from an API
  • Parse data returned from an API into useful products for our own purposes


listLesson sequence

  1. Discuss course plan: project design for course
  2. Grade card proposals
  3. SOSOs
  4. API Fundamentals: Donors Choose API and sample tweaking according to the specification below
  5. API Design project and worktime

program objective

assemble statistics on project by keyword

program requirement 1

The program currently is assembling data about the average cost of all projects which match a keyword in a file. We are also gathering bunches of other project data. Tweak the existing code to create a tally of how many of the projects in each keyword category are classified as "studentLed" which is a key in a dictionary inside the returned JSON file

playlist_add_checkMid-week ToDOs

Complete your API project and upload it to your github account.

arrow_upwardback to schedule

Tuesday, 23 October 2018

Packaging, planning and sharing

live_helpGuiding questions

  • What skills should a student reasonably have to jump into python 2 without python 1?
  • How can we package and comment python code for accessibility to new pythonistas?


listLesson sequence

  1. Schedule review and planning: No guest today--27 Nov is next target.
  2. Python II entry competency project
  3. Code comments and code portability
  4. Featured functionalities banners
  5. Mini skill sharing

playlist_add_checkPeer tutorial subjects

  1. 1: Using modules: (Lutz 2013, 5th ed: Part V chapters 22-24 are all on modules. We want to ingest the highest level concepts here with a short exercise and challenge.
  2. 2: Comprehensions and generators: List, dictionary, etc. (Lutz 2013, 5th ed: chapter 14 with emphasis on pages 441+ for comprehensions. Ch. 20 for comprehensions and generators)
  3. 3: Regexps: (Use python.org's regexp howto and the more detailed module documentation on re)
  4. 4: Object-oriented python: (Lutz 2013, 5th ed: The entire part VI is on classes and OOP--good luck!)
  5. 5: Exceptions: (Lutz 2013, 5th ed: Basics are in ch. 33 with the rest of part VII related to more advanced topics)
  6. 6: Functions and tools: global/nonlocal., lamda, yield, etc. (Lutz 2013, 5th ed: review ch. 16 on function basics; read chapter 19 on advanced functions. Steer clear of yield, since generators will use these.)

sendPeer tutorial specs

mini-project objective

Provide us pythons with 20-30 minute "crash courses" on topics that may not be worthy of an entire evening in python II

quick reference 1/2 sheet

Read the book and python.org documentation on your subject. Run some code. Distill down the example code provided in the references to the essential module and topics only. Also, boil down the reference content to diagrams, figures, or bulleted lists of core ideas or topics.

Assemble a 1/2 page (with the page in landscape orientation) quick reference for your topic that neatly arranges this information

prepare a sample activity

Drawing from examples of others, create a 10-15 minute coding exercise that you write entirely on your own using some sort of consolidating topic of your choosing (i.e. Eric using airline safety and metallurgy to discuss statistics). The example should include essential functionality of your topic and should be expandable.

Comment your example code and push it up to your GitHub account

propose extension exercises

Create a short list of continuation exercises for somebody to guide their further explorations into your topic. Review one of Eric's extension exercise examples from Java.

Document these extensions either in a text file on GitHub or in comments in your sample code.


  1. Featured python code snippet and output banner
  2. Commented, packaged, and documented projects: 2x up to GitHub and link on this site

arrow_upwardback to schedule

Week of Tuesday 13 NOV

Developing python 2 entrance challenge

live_helpGuiding questions

  • Can we learn from/while "taking a test?"
  • What kinds of thinking lead to meaningful test questions?


listLesson sequence

  1. Review sample python 1 questions from the resources above and those you find on your own
  2. Review the core content areas of our course: data structures, looping, and web/api interaction
  3. Study the specification below for creating a two-task instrument to gauge a student's readiness for entrance into our CCAC Python 2 course
  4. Jot down a list of what you think are the core skills students should have acquired in Python 1 to be prepared for python 2.
  5. With your list in mind, engineer the two-task instrument. For each task, create specs, sample output, success criteria, and a possible solution
  6. Upload your content to your git-hub account
  7. Create a printable PDF version and upload it to our shared one-drive space

listInstrument meta-specifications

These are the specifications for your python 2 readiness test specification

python 2 readiness assessment overview

Students engaged in programming stuff at CCAC exhibit a wide range of skills across languages and technical abilities. Some students with prior programming experience or a very tenacious work ethic may have skills sufficient to jump right into python 2. Design an assessment instrument that can be used to gauge a student's readiness for python 2

task specs

Using this very box as a model, engineer 2 program specifications:

  1. A more straightforward python 1 task, such as implementing nested if-logic or basic looping with simple break conditions
  2. A more challenging python 2 task, such as conducting basic file i/o and processing the results

Creating tasks that are mildly interesting will help students engaged

sample output

Include in your specification sample program output for each of your two programs which the student can view as they build their program

success criteria

Using Eric's Intro to Java assessment instrument and rubric as a guide, declare a standard for determining what kind of responses to your two program specs would constitute readiness for python 2.

This could take the form of a paragraph describing what kind of code structures should be present in the source code of each task and what they should do. Obviously, you'll need a criteria for each task

solution code

Code to your own specification and upload your source to your dedicated repository linked at technologyrediscovery.net. Don't include a link to your source in your PDF


  1. Relevant source code posted to your github code repo
  2. Your assessment instrument uploaded as a PDF to our shared drive

arrow_upwardback to schedule