Computer architecture: Processor and memory. Their different roles.
The concept of an imperative language.
Python is a language. Difference between interpreted languages and compiled languages.
Getting into the logic of programming. This week we'll "program as an exercise in logic intuition," rather than learning the basics.
Playing with Python.
variables
x = 3
name = "hello"
keywords: and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try
Printing strings. What's a string?
Printing numbers. What's a number? What is the difference between "3" and 3?
Understanding the difference between an editor and the shell (console) windows
Looping through a list and outputting formated information
Friday
Comments on Lab 1
Variables
Rules for labeling a variable
CamelCase for regular variables, uppercase for constants
Thinking of a variable as a box, or drawer.
Variables can switch contents
Types of values: int, float, string, char
The concept of an algorithm (Section 1.7 in textbook)
Must be unambiguous, executable, and terminating.
Example: calculating the return on a bank account with a yearly interest rate.
Review of the week: some of the concepts covered: variables, literals, integers, reals, strings, functions, statements, comments
Preparation for Lab #1 <== Please do this if you plan on using your own laptop during the labs
This week, you should read Chapter 1 in Python for Everyone, up to Section 1.6, included.
Read the article on pair programming. We will discuss it in class during the second week of class.
Week 2 2/3
Saturday/Sunday: Moodle Quiz on Chapter 1. Go to Moodle, select CSC111, and locate the Quiz in the "Week 1-Chapter 1" section. (If I have let you in the class, but you are not officially registered yet, please send me an email (dthiebaut@smith.edu) so that I can add you to the moodle roster. )
The two-letter Id needed to submit your program is available here!
Meet Guido van Rossum
Variables:
They are labels for boxes containing information. Boxes in memory.
Different types. Can be combined together.
Values can be assigned to them with =
Operators: + - * / // %
Teller Machine example: given some amount of $ to withdraw from the machine, figure out the number of $20-, $10-, $5- and $1-bills. Here's the program we finished with in class.
Wednesday:
THERE WILL BE CLASS AND LAB TODAY! I AM ALREADY IN FORD HALL --DT
Read the article on pair programming. We will discuss it in class on Wednesday.
Finish reading Chapter 2 by the end of this week.
Read Chapter 3 up to Section 3.6 3.8 (not included) before Monday 2/10.
Add
Week 3 2/10
Saturday/Sunday: Moodle Quiz #2 on Chapter 3. Go to Moodle, select CSC111, and locate the Quiz in the "Week 2-Chapter 3" section. The quiz closes Monday at 10:59 a.m.
Saturday/Sunday: Moodle Quiz on Chapter 4: While Loops. The quiz will cover only While loops, from Section 4.1 to 4.5 included. The quiz will close right before Monday's class.
Monday:
Watch the exchange between the robot played by Robin Williams and his owner, played by Sam Neil in the 1999 movie Bicentenial Man". Here one of the two "people" having a conversation is an ultra-logical being: a robot, who is not fully aware of the subtleties of the art of (human) conversation:
(advance the movie to 7 minutes and 10 seconds)
Debugging with print() statements: it works! Applying this technique to an exercise
The different parts of a while loop. The flow of control.
Reading Chapter 4, first half on While loops for Monday 2/17, second half on For loops during the week.
Week 5 2/24
Saturday/Sunday: Moodle Quiz on the second half of Chapter 4: for Loops. The quiz will cover only for loops, from Section 4.6 to the end of Chapter 4. The quiz will close right before Monday's class.
Monday
For-Loops: review what they do, how they work
Playing with sound files
A bit of physics
Physics of sound: A metal plate is connected to an oscillator and frequency is increased...
The source of waves] (1933). You may skip after the first 6 minutes.
defadd(a,b):returna+b# try the above function with numbers, ints, floats, and strings!defintAverage(a,b):return(int(a)+int(b))//2defprintWinner(human,computer):ifhuman==computer:print("It's a tie!")elifhuman<computer:print("I WIN!")else:print("I let you win...")
If the assignment does not specify that the program will input data from the keyboard, don't use input() statements!!!
PAY ATTENTION TO DETAILS!!!
Add blank lines to highlight natural (logical) divisions
Break long lines into shorter ones
One should understand the structure of a program by scanning it quickly.
The dynamics of returning from a function
deff1(a,b):c=a+bifa<c:returnprint("case 1")ifa>0:print("case 2")else:print("case 3")returnprint("a=%d b=%d c=%d"%(a,b,c))# what's the output generated by the following calls? f1(3,2)f1(-3,2)f1(3,-2)f1(-3,-2)
Working with files. Files are an essential part of a computer, and they are maintained by the operating system.
How hard disks work:
The evolution of hard disk technology. Examples
The evolution of programming languages.
How are characters stored on disk (and in memory)?
ASCII Table (American Standard Code for Interchange of Information)
UTF-8 ((Universal Character Set) Transformation Format)
Typical file operations:
open file for reading
read whole file into a variable (string or list)
close file
or
open file for writing
write one or several variables to file
close file
Examples:
Write
# write some variables to filename="Smith College"address="1 Elm st., Northampton, MA 01063"file=open("college.txt","w")file.write("%s\n"%name)file.write("%s\n"%address)file.write("Amherst College\n")file.write("Amherst, MA, 01002\n")file.close()
Read
# read the same file back and print all the linesfile=open("college.txt","r")forlineinfile:print("line =",line.strip())file.close()
An often forgotten combination of operators: "not in", as in "if x not in List"...
A word about Homework 7
height=100yPairs=[]stripeHeight=height//8foryinrange(0,height,height//4):yPairs.append((y,y+stripeHeight))print(yPairs)forpairinyPairs:print("Stripe ys: ",end="")foryinrange(pair[0],pair[1]):# display a full row of pixes at 7print(y,end=" ")print()
Read Chapter 7 on Files and Exceptions. We are going to concentrate on text files, reading text files and writing text files, and on handling exceptions. You may skip Sections 7.3 and 7.4.
Week 11 4/7
Saturday/Sunday: Moodle Quiz on Chapter 7 on Files and Exceptions. The quiz will close right before Monday's class.
Something to learn by heart: LIST.append() does not return anything,, but STRING.replace() does
Something to remember: If a function returns something of a given type, it must always return something of this type. The exception is that it can return None which does not have a type
fromgraphicsimportGraphicsWindowMAXWIDTH=800MAXHEIGHT=600defmain():win=GraphicsWindow(MAXWIDTH,MAXHEIGHT)canvas=win.canvas()#--- add new code here ---win.wait()win.close()main()
We continue working with objects and classes this week, so the material covered in Chapter 9 is definitely still a good reference to visit and visit again.
We will use objects in the context of graphics this week, so the material you already read in Chapter 2 will be a good reference for us.
One of the appendices in the book has a good coverage of the graphics library (starting Page A-24) and all the methods available.
Class inheritance is covered in Chapter 10 of the book. Read the first 4 sections (stop at Section 10.5, excluded).
Week 13 4/21
Saturday/Sunday: Moodle Quiz on Classes and Inheritance. The quiz will close right before Monday's class.
a={'dog','cat'}b=set([])a.add('dog')a.discard('cat')len(a)sorted(a)a.intersection(b)a.union(b)L1=[1,2,3,3,3,3,3,4,5]d=set(L1)# Exercise: take a list and remove all its duplicates# Exercise: count unique words in a string, with lists, with sets
Sets and Dictionaries are covered in Chapter 8. Read Sections 1 and 2, and stop at 8.3.
Week 14 4/28
Monday
Wednesday
Friday: Final Take-Home EXAM
Reading
Links and Resources
Map of Smith College
Full Map
Reduced Map
Dates of Construction for Smith Buildings
The dates for the construction of different buildings on campus are available here
A Skeleton Python Program for Displaying An Image
# Skeleton program for displaying a gif image.# D. Thiebaut# Warning: will not work with a jpg or png image! If you # need to convert your image to gif, use a Web service.#fromgraphics111import*importtkinterastkMAXWIDTH=800MAXHEIGHT=600# ========================================================# Main Program# ========================================================defmain():gifFileName="SmithMapSmall.gif"# open the window and get access to its canvaswin=GraphicsWindow(MAXWIDTH,MAXHEIGHT)canvas=win.canvas()# put gif image on canvas photo=tk.PhotoImage(file=gifFileName)canvas._tkcanvas.create_image(0,0,image=photo,anchor=tk.NW)# wait and respond to events, or comment out and make the program# stop as soon as car disappears.win.wait()win.close()main()
A Skeleton Event-Driven Program
# A Skeleton event-driven program# D. Thiebaut#fromgraphics111import*MAXWIDTH=800MAXHEIGHT=800defmouseEvent(win,canvas,x,y):globalmenubutton=menu.buttonClicked(x,y)ifbutton==None:returnifbutton=="LeftArrow":returnifbutton=="RightArrow":returnifbutton=="Minus":returnifbutton=="Plus":return# ========================================================# Main Program# ========================================================defmain():globalmenu# open the window and get access to its canvaswin=GraphicsWindow(MAXWIDTH,MAXHEIGHT)canvas=win.canvas()canvas.setCallbackFunction(mouseEvent)# add a menu to the windowmenu=Menu()menu.draw(canvas)# wait and respond to events, or comment out and make the program# stop as soon as car disappears.win.wait()win.close()main()
Graphics Library used in Textbook
It is available for download here. Once downloaded, unzip it and move it to the directory where you are developing your programs.
All Demo Programs
A selection of programs created in class can be found here
On Line Python books
disocovermagazine.com blog. Check out the answers posted by many readers. They contain some interesting links that you may find useful!
Python keywords
The list of all the reserved words of the Python language
and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print