Course Lectures, Examples and Readings:

Required Books:

Detailed topics and readings for each meeting:


Main topics



Class Introduction:
What is computer Science? What is an algorithm?
How to install, run and use Python’s software needed for this class.
Introduction to Programming in Python


Chapter  1 from Jennifer Campbell's book.

Please note that a free copy of this book (Downey’s book) is available online at:
EXAMPLES: hello1,, addition1,


Variables, data types, statements and expressions: Lecture 1 & 2

Chapter 1 & 2 from Allen Downey’s book., addition2, division, division2, average1, average2, mod1,year.p,



Control flow: Branching (If, elif, and else.)

Boolean logical operators and expressions.
Branching: Selections statements (If, elif, and else.)

Chapters  2 and 4 from Allen B. Downey's book.
Chapter  2 & 3 from Jennifer Campbell's book.

EXAMPLES: Control Structure


Repetition (Loops): Repetition (Iteration using for and while loops.)
for loops, while Loops , nested Loops


1) Integer Random numbers: Need to import random at the beginning of your program

import random

Please note that using random.randint(a,b) produces the following range:
# Return a random integer N such that a <= N <= b.
#Example: random.randint(1,6) produces 1 <= N <= 6.

This can produce 1 or 6 or 4 or 3

Chapters 5.1-5.7 and 7 from Allen Downey’s Book.
Chapter  7 from Jennifer Campbell's book.

EXAMPLES:Repetition (Loops), nested loops, Sentinel loops: While sentinel loop (user will stop loop)


ists: Create a list and use list.append() and list.remove() to add elements to the list:, Month selected at random from a



Reading names from a file: || text file: names.txt

Readings numbers from a file: || text file: grades.txt

Writing to a file:

Pythons Modules (Math, and Random): Examples of Defined Functions: random.random(), random.randint(min, max), len(), random.choice('abc'), math.sqrt(x), math.pow(x, y),


Chapters 7, 8 and 11 from Allen Downey’s Book

Book examples: Lists, file and Exceptions

Review of built in functions in Python (this is a good review for all functions covered so far including String and lists.


Modular Programming:  Structuring larger programs (Modules and Functions): Lectures: Functions

Pythons Modules (Math, and Random) , python defined Functions, User Examples of Defined Functions: random.random(), random.randint(min, max), len(), random.choice('abc'), math.sqrt(x),
math.pow(x, y),
User Defined Functions:

Chapters 3 and 6 from Allen Downey’s Book.

Examples of Defined modules and functions: Math, and Random.
Integer random number examples:, random_numbers1, Roll dice 100 times ,Compute average for 20 random numbers between 1 and 1,000,000, Float random numbers examples (also printing only 2 decimal values): random_numbers2,

Random numbers & user defined functions: Random functions, generate a random word (5 letters), netid (generated randomly)

Examples of User-Defined functions that don't return a value:
green Eggs,, Square numbers ,Square and cube Numbers, Square, cube and print, shapes1, shapes2 (not efficient-- see shape 3 for a better example)

Examples of Functions that return values: Square numbers, Converting temperatures

It's possible for a python function to return multiple values at the same time (not allowed in other programming languages):Multiple Returns

Local Variables: Scope of local variables in functions

Global variables: Scope of Global variables

Draw shapes using functions: Shapes3 , function to draw a Box