Professor Sana Odeh, Fall 2013: Course Lectures, Examples and Readings:

 

Exams: FINAL EXAM: December 16, 10:00am - 11:50am, WWH 102

Schedule:

Detailed topics and readings for each class/meeting. Please note that this is a tentative schedule and topics might change during the semester.

Day Date Topic Reading done Assignment due
1 9/4

Class Introduction:

Download Lecture
What is computer Science?
What is an algorithm?

Input, Processing, and Output

Chapter  1 from Gaddis, Visual QuickStart  and Allen Downey’s book

Please note that a free copy of Downey’s book is available online here.

 

2 9/9

Introduction to Programming in Python:

Download Lecture
Variables, data types, statements and mathematical expressions.

How to install, run and use Python’s software needed for this class.

Readings: Chapter  2 from Gaddis, chapters 2 and 3 from Visual QuickStart book , and chapter 2 from Allen Downey’s book

Class Examples: hello1, hello2, average

Practice Assignment(No need to submit any thing to me as this is a required practice activity):

1) Install python software version 3.3.2 on your computer (view instructions here from Prof Joshua Clayton)

2) Practice writing/debugging python programs:Open Idle (Idle is the Software that comes with Python and allows you to write/edit and run/execute your python program).
Then, write several python programs to print numbers (int and float), and strings.
Make sure to save each program with .py extension.

3) Practice writing/debugging/exciting python code using the interactive python interpreter (Python Shell or command line).

3 9/11

Variables, data types, statements and mathematical expressions.

Download Lecture

Readings: Same as above

Class Examples: addClassExample

Working with String data types Example: stringdata.py

 

 

Assignment 0   due 9/18 by midnight

4 9/16

Simple Computations using the // (for integer division) and % "Mod" operators

Intro to Control Structure (If, and else) (Download lecture)

Readings: Same as above

Working with math operator and evaluation mathematical expressions: addition1, addition2,division, division2

More on Math operators:float division (/), int division (//) and  modulus  or mod( %):

intdata.py, mod1, dollarchange.py, Reverse Number

 

 
5 9/18

Control Structure (if, elif, and else):

- Making decisions, Branching: Selections statements (If, elif, and else.)

- Boolean logical operators and expressions.

(Download lecture)

 

Control structure examples: age, evenodd

Examples:freeplaneticket.py,evenodd ,grade1, grade2, grade3, grade4,temperature

 

 

 

Assignment 1 (control Structure)
6 9/23

Control Structure Continued

Introduction to Repetition Structure using While Loops (Iteration/Repetition):

(Download lecture)

Control Structure examples:

Readings: Chapter  4 from Gaddis, chapters 4 from Visual QuickStart book , and chapter 5 from Allen Downey’s book

Control Structure Examples:

boolean, and truthTables

Bouncers: bouncer1.py, bouncer2.py, bouncer3.py, bouncer4.py, bouncer5.py, bouncer6.py, bouncer7.py

While loops examples: counting using while,while stars1.py, stars one line,whilecount3, square numbers ,and even_odd loop

 

 
7 9/25

Repetition Structure using For  Loops (Download lecture)

 

Formatting using Format()

Chapter  5 from Gaddis, chapters 4 from Visual QuickStart book , and chapter 7 from Allen Downey’s book

For loops examples: stars1.py, stars_sameline.py,for Loop to print 5 stars, forcountby1, forcountby5,count

 

 

 

 

Assignment 2 (Calendar Application)
8 9/30

Repetition Structure: Sentinel Loops

Sentinel while loop example: While sentinel loop (user enters a value to stop loop), sentloop.py, sentloop2.py

Special loop to manipulate strings: example

for letter in "python":

print (letter)

View this example:

1) Use a for loop to extract each letter from a string

2) Use ord() function to convert from letter to it's equivalent ASCII value (number)

3) Use chr() to convert the ASCII value (Number) to it's equivalent letter.

 

 

Assignment #3 (Loops)
9 10/2

Loops (Iteration/Repetition):

Generating random numbers (we will spend more time on random numbers during next week):
Integer random number examples:random_numbers1

 

Float random numbers examples (also printing only 2 decimal values):

1) Integer Random numbers:
random.randint(a,b)
: 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

 

 

 
10 10/7

Repetition/Iteration using Loops

 
11 10/9

Midterm Review

- 10/ 14

No class (Fall break)

12 10/16

Midterm #1

 
13 10/21

Repetition/Iteration using Nested Loops (Loops within loops): Nested loops lecture

 

Using nested loops to draw 2D shapes: stars1.py, stars_sameline.py, square, rectangle,
Right Triangle1 using while,Right Triangle using for, Left Triangle2, DOWN-POINTING TRIANGLE, Up-POINTING TRIANGLE

Nested loop using seconds and minutes, sec. min. and hours in one day,

Weaving a simple and pretty Kilim rug (helpful for the assignment): simple rug

Rug Art Example: viewing regular patterns in kilims from Iran and Bulgaria from Kilims: A Buyer's Guide by Lee Allane

 

 

 

Readings: Chapter 5 from Gaddis, chapters 4 from Visual QuickStart book , and chapter 7 from Allen Downey’s book Assignment # 4   (Nested Loops)
14 10/23

String built-in Methods

User-Defined Functions: Designing your own functions

Using len() to return number of character in a string: len()

LECTURE: Strings

Book examples: Strings

 

Strings Examples same example but using string methods (built in functions) to convert from caps to lower case and the reverts (more efficient): using str.lower() & str.capitalize()

letter Counter using For loop,

Space and commas counter

Count lower and upper case letters

String methods: replace(), find(), count(), and split() example

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

Readings: Chapter  9 from Gaddis, chapters 6 (Regular expressions not included) from Visual QuickStart book , and chapter 8 from Allen Downey’s book

Formatting output: format output

Multiple assignment and swaps: assignments,

 

 

 

15, 16 and 17

10/28 and 10/30

and 11/4

Functions: User-Defined functions: Lecture

Examples of User-Defined functions that don't return value(s)

greengages, greenEgfgs_withFunctions2.py

Square numbers, Square and cube Numbers, Square, cube and print, shapes, shapes2, Shapes3 , function to draw a Box

Readings: Chapter  3 and 6 from Gaddis, chapters 5 from Visual QuickStart book

 

Functions that require arguments similar to Math.pow(2,3): 2, and 3 are "arguments" or random.randInt(1,6). When passed to function, they become "parameters":

 
178 11/6

User-defined function that return value(s):Fruitful Functions: Functions that return one values: Converting temperatures

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

 

Functions that returns one values: Converting temperatures

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

Creating your own module:

  1. Define a module ( a program with only functions): I called my module calc.py
  2. Create a separate program and make sure to import the the module calc, and also use main() function in this program. I called it (calmain.py)

 

 

You can use multiple ways to import functions from modules:

  1. import moduleName
    • then when you use the module from another program, you need to write: modulename.functionName()

    Or, use:

  2. import from moduleName *
    • then when you use the module from another program, you can just write function name without using the module name: functionName()
Assignment 5 (Functions and Modules)
17 11/11

Scope of functions: Local and Global variables:

Local Variables: Scope of local variables in functions

Global variables: Scope of Global variables

How to change global variables in other functions changeglochbal.py ||global.py

 

 

18

11/13

Review functions and modules

 

 

 

 

19

11/17

Midterm# 2 Review

| Midterm 2 review || Midterm 2 sample

20

11/20

Midterm #2

21, 22, 23

11/25, 11/27, and 12/2

Lists: LECTURES: LISTS

 

More list examples: list1.py, example 2

What is the output of this program: list3.py

LIST methods: Create a list and use list methods list.append() to add new elements to list, list.reverse() to reverse list elements, list.count() to count how many times an element appears in list, list.sort() to sort list, and list.remove() to remove an item from list: example 1,

Loops to use with lists:

1) Special loop to use with lists:

friends = ["Joe", "Zoe", "Brad", "Angelina", "Thandi", "Paris"]
for friend in friends:
print(friend)

2) Loop using numeric index:
xs = [1, 2, 3, 4, 5]
for i in range(len(xs)):
xs[i] = xs[i]**2

Selecting an item randomly from a list:list_parlam.py,

Using a function to initialize values in list using random.randint()

Use User-defined functions with lists (how to pass lists to functions):list with function, list2.py,, list_months.py, listfunc.py, pick month at random using list, random and functions

 

using the operator "+" and "*" with lists:

a =[1,2]

b = [3,4]

new = a + b

print(new) # prints [1,2,3,4] the "+" joins two lists

new = a * 3

print(a) # prints [1,2,1,2,1,2] the "*"reproduces multiples of the list

 


VisualQuickstart Python- Chapter 7: Pages 100-101, and 105 to 114.

Chapter 8 from Gaddis,pages 295-332.

and chapter 11 from Allen Downey’s book

Important Notes:

id:

print(id(list)) prints the unique address where list is stored in memory

 

"in" and "not in" keywords: To find if an item in or not in list:

Example:

>>> horsemen = ["war", "famine", "pestilence", "death"] 
>>> "pestilence" in horsemen 
True 
>>> "debauchery" in horsemen 
False >>> "debauchery" not in horsemen True

 

list slices (similar to string slicing):

>>> a_list = ["a", "b", "c", "d", "e", "f"] 
>>> a_list[1:3]
['b', 'c']

>>> a_list[:4]
['a', 'b', 'c', 'd']
>>> a_list[3:]
['d', 'e', 'f']

>>> a_list[:]
['a', 'b', 'c', 'd', 'e', 'f']

>>> a_list[-1]
[ 'f']

>>> a_list[::-1]

['f', 'e', 'd','c', 'b', a']

 

 

Assignment # 6

 

24

12/4

Input/output (I/O): Reading data fromextrenal files and writing data to external files:

Writing text/string (words) to a file called words.txt

Using readlines() to read from file words.txt

reading text/string (words) from file words.txt

reading grades from file grades.txt

Search, read and write to a file: findinfile.py ||findinfile.txt

search example 2: serach1.py ||text file to read and search || file that was written from our program

Reading from external files from the web (text and html:

reading files from the web (text file)

Getting data (text) from a URL (web):

urldataList.py || link to file animals

Getting data (HTML) from a URL (web): urldata2.py

VisualQuickstart Python- Chapter 8 and chapter 9

Chapter 7 from Gaddis

and chapter 13 from Allen Downey’s book

 

25

12/9

(Not Included on the final)

Introduction to Graphics using Turtle: Turtle Notes

Examples: turtle1, turtle2.py, turtle3.py, example 4,

turtle5.py, turtle7,

(using objects):

example 8, example 9

 

 

(Not Included on the final)

Tutorial: chapter 4 from Allen Downey’s book

Turtle Reference:

 

26

12/11

Final Review:

How to study for final ( Make sure to do all of the readings, review all of the homework, class notes, examples, all samples midterm questions and midterms:)

Review Questions for list and read/write to file| answers  

 

 

 

FINAL EXAM: 

December 16, 10:00am - 11:50am, WWH 102

 

   

 

Tutoring for this class (Additional Help):

Please see lab tutors in person for help or email our Etutor Rachel Rosen (csciua02@cs.nyu.edu).

Lab Tutors (Make sure to check the Tutoring website for updated tutoring hours):

MON: Ben 12:15-3:15, Casey 2:00-3:15, Eric 3:30-4:45, Casey 5:00-6:00
TUES: Casey 12:00-1:45, Ben 12:15-2:15, Eric 2:00-3:15, Casey 5:00-6:00
WED: Eric 11:00-12:15, Ben 12:15-3:15, Casey 2:00-6:00, Eric 3:30-4:45
THURS: Eric 12:30-3:30, Ben 12:15-2:15, Casey 5:00-6:00
FRI: Eric 5:00-7:00

E-tutor: Rachel Rosen - send email to: csciua02@cs.nyu.edu