CSC111 Class Page 2014

From dftwiki3
Revision as of 09:14, 2 May 2014 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 09:58, 7 January 2014 (EST)


Main Page | Syllabus | Weekly Schedule | Links & Resources | Piazza | TA Hours | WHITE




Prof and TAs

Dominique Thiébaut email
Dept. Computer Science
Ford Hall, 356.
Telephone: 3854
Office hours Monday, 2-4 p.m., Wednesday 1-3 p.m., and by appointments

 



To see when and where TAs are available this week, click here.


Weekly Schedule


First Half (Feb-Spring Break)


Week Topics Reading
Week 1
1/27
  • Monday
    • A look at the syllabus
    • The Python integrated environment, named Idle
    • Python is free and can be downloaded from the Python download page
    • Example of a Python program

    • What is a programming language? The idea of a Syntax
    • Python keywords
    • A simple "Hello World!" program in Python
    • Errors
  • Wednesday
    • 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
    • Camels.png
      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




  • Reading
    • 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. )
  • Monday
    • Message from student liaisons
    • The two-letter Id needed to submit your program is available here!
    • Meet Guido van Rossum
      VideoLogo.png

    • 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:
CollegeHallSnow02052014.jpg
    • THERE WILL BE CLASS AND LAB TODAY! I AM ALREADY IN FORD HALL --DT









VideoLogo.png
FulghumAllINeedToKnow.png
    • Discussion of the pair-programming article in class.

    • Continue with ATM/Teller machine example: The importance of pseudo-code, and going one step at a time.
    • Changing a float into an int, and vice versa
    • Functions: print(), abs(), trunc() (predefined)




VideoLogo.png
  • Reading
    • 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.
  • Monday
    • A quick glimpse of what's ahead: Code Blocks
    • If-statements
      • Flowcharts
      • The idea of boolean values, George Boole (1815-1864), 2-way directionals
      • Relational operators < <= > >= ==, !=
      • Exercise 1: Revisiting the ATM program
      • Exercise 2: Printing a tight box around 3 strings of unknown length: FindMax.py


  • Wednesday
    • Poll for Lab Section 1 students
    • Continue exercises from Monday
      • Exercise 3 (tricky!): Same as Exercise 2 but using this approach: print( "|%30s|" % name ), where 30 is the max
      • More exercises!
      • Negating a boolean expression (point inside a rectangle)
      • Boolean variables
      • Rock, Paper, Scissors


  • Thursday
Enjoy the day off! Enjoy the snow! Please do Lab 3 on your own and pick a time when TAs are available to help you out."




  • Reading
    • Finish reading Chapter 3 this week!
Week 4
2/17
  • 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)



  • Wednesday: RALLY DAY Lab 1 will be split in 2 sections, one Wed. 7-9 p.m., and one Thursday 7-9 p.m.. Both will be in Ford Hall 342.


  • Friday
    • Comments about Lab #4, Challenge 4:
Modify the program above so that it stops 1) if the user enters -1 2) or when the sum of the numbers is greater than 20.
    • VideoLogo.png
      VideoLogo.png
      Working with sentinels
    • Example 1
    • Example 2 , reading Emily Dickinson's poetry
    • Two illustrative videos for running Python on the command line.









  • 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...
            file = pickAFile()
            sound = makeSound( file )
            blockingPlay( sound )
    • Basic functions can be found here
    • Exercise 1: reduce the sound intensity by half
    • Exercise 2: play the sound file backwards
    • The print() function is getting more powerful by the minute! sep and end parameters!


  • Wednesday
    • The print() function is getting more powerful by the minute! sep and end parameters!
    • Simple sound modification exercises.


DontBeAChimp.png
  • Friday





  • Reading
    • Chapter 4 on For-Loops. The quiz for Monday will ask questions about material seen in class the week of 2/24.
Week 6
3/3
  • Saturday/Sunday: Moodle Quiz on for Loops. The quiz will close right before Monday's class.


  • Monday
    • Q&A
      • What is printed by this test?
if False==False:
   print( "Chocolate" )
else:
   print( "Spinach" )
    • Functions.
      • Definition
      • Examples of functions that print simple messages.
def greetings():
    print( "-----" )
    print( "Hello" )
    print( "-----" )
      • functions can be called inside loops...
      • Playing a game with functions
      • function parameters: creating a function that prints a string with a box around it.
      • Playing more sophisticated games


def add( a, b ):
     return a+b

# try the above function with numbers, ints, floats, and strings!

def intAverage( a, b ):
     return  ( int(a)+ int(b) )//2

def printWinner( human, computer ):
     if human==computer:
         print( "It's a tie!" )
     elif human < computer:
         print( "I WIN!" )
     else:
         print( "I let you win..." )



  • Friday


    • Top-Down design
    • Review of Lab #6
    • Comments on Homework 4.
      • Look at the solution programs
      • What should you put in a header?
      • 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
def f1( a, b):
	c = a+b
	if a < c:
		return
	print( "case 1" )
	if a > 0:
		print( "case 2" )
	else:
		print( "case 3" )
		return
	print( "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 )

  • Reading
    • We're starting learning about functions this week. They are documented in Chapter 5 of the textbook.
    • We'll cover functions that do not return values first, then functions that return values next.
    • As soon as we understand functions enough we'll jump back to Chapter 4 to look at nested for-loops.
Week 7
3/10

No Quiz this weekend (3/8, 3/9)!

  • Monday
RGBColorDecimal.gif
    • redEyes.bmp
    • catHat.bmp
    • Nested for-loops with Python Tutor
    • Digital images. Pixels, colors, RGB format, width, height, coordinate system.
      • Exploring RGB system with JES:

color=pickAColor()

    • JES functions for processing images:
    • Processing images:
      • Changing the colors of an image
      • Making an image black and white
      • Swapping Red, Green and Blue components
      • Adding a border to the image
      • Changing the red eyes to black
      • Skeleton Program
  • Wednesday

MelonCatInFog.png
Youyou's cats, created during Lab 7 Session 1


  • Friday
    • Go over Lab #7 solution programs
    • RealProgrammersButton.png
      Comments on Homework # 5 (returned) and Homework #7 (due Thursday after the break)
      • Pay attention to details!
      • Imports at top
      • Make the computer compute!



  • Reading
    • A Good introduction to image processing with JES can be found here.


Spring Break



Second Half (Spring Break-May)


Week Topics Reading
Week 9
3/24
  • Monday
    • Lists
    • Lists are containers. Two types of lists: [...] (mutable) and (...) (immutable)
    • Review: creating a list. Empty list and append operation.
    • Review: len() and indexing
    • New: indexing from the end
    • Review: traversing lists
    • New: list reference. Lists are shared!
    • New: inserting elements in a list
    • New: testing if an element is in the list with in
    • Exercises and Solution program





  • Reading
    • Read Chapter 6 on Lists
Week 10
3/31
  • Monday
    • A word about the quiz
    • A word about the Wolfram language

    • Price of a bit
technology cost speed

RAM:

8GB @ $80 ( 0.01 cents/MB )

6,000 to 17,000 MB/s

SSD

256GB @ $190 (0.0007 cents/MB)

600 MB/s

Hard Disk

2 TB @ $160 ( 0.00008 cents/MB)

90 MB/s

    • 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:
      1. open file for reading
      2. read whole file into a variable (string or list)
      3. close file
    • or
      1. open file for writing
      2. write one or several variables to file
      3. close file
    • Examples:
      • Write
# write some variables to file
name = "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 lines
file = open( "college.txt", "r" )
for line in file:
   print( "line =", line.strip() )
file.close()


  • Wednesday
    • Remember to use the docs.python.org pages for reference!
    • What is the file path?
      • Under Windows 7
      • Under Mac OSX
      • The concept of Current Directory
      • The concept of Parent Directory
      • The concept of the Root of the file system
      • The concept of a tree data-structure
    • Writing text to file
    • Reading text from file
    • Writing numbers to file
    • Reading numbers from file
    • Creating a log


  • Friday
    • Remember to use the docs.python.org pages for reference!
    • An often forgotten combination of operators: "not in", as in "if x not in List"...
    • A word about Homework 7
height = 100
yPairs = []
stripeHeight = height//8

for y in range( 0, height, height//4 ):
    yPairs.append( ( y, y+stripeHeight ) )

print( yPairs )

for pair in yPairs:
    print( "Stripe ys: ", end="" )
    for y in range( pair[0], pair[1] ):
        # display a full row of pixes at 7
        print( y, end=" " )
    print()
    • (early end of class: Presentation of the Major)



  • Reading
    • 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.
  • Monday


  • Wednesday
    • 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
    • Back to Example 2 from Monday's class
    • Rules and definitions
      • The interface
      • the DOT notation.
      • Private versus public member variables
      • Private versus public methods
      • What if a method needs to call another method of the same class?
    • Example 3: Creating a Dog class (use the Person class as example), with two member variables:
      • a tag name (string)
      • a vaccinated status (boolean)


  • Friday (Visit by admitted students)
    • Reminder: Quiz during the weekend on Python objects and classes
    • int to month name: an easy solution
def nameOfMonth( num ):
    months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
    return months[ num ]
    • is "Hello" in the user input?
ans = input( "> " )
if ans.lower().find( "hello" ) == -1:
     bePolite( )




  • Reading
  • We will skip Chapter 8 and move on to Chapter 9 this week.
  • Read Chapter 9!
Week 12
4/14


  • Wednesday


    • Graphics (Covered in Chapter 2)
from graphics import GraphicsWindow

MAXWIDTH = 800
MAXHEIGHT = 600

def main():
    win = GraphicsWindow(MAXWIDTH, MAXHEIGHT)
    canvas = win.canvas()
    
    #--- add new code here ---


    win.wait()
    win.close()
    
main()
      • Setting the color inside shapes
    canvas.setFill(  red, green, blue )
      • Drawing rectangles:
    canvas.drawRect( x, y, width, height )
      • Drawing circles
    canvas.drawOval( x, y, width, height )
CarForGraphics.jpg



  • Reading
  • 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.


  • Monday
    • Adding motion to graphic objects. Example
    • Resizing a graphic object. Example
    • CallBackSetupForGraphics.png
      A new concept: Event-Driven Programming
    • Adding event-driven capability to out graphics library: graphics111.py
      • Circle, Wheel, Rectangle and Polygon classes
      • Menu class
      • Example Programs


HeleneVisentin.jpg







  • Friday
    • Animated Objects



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




  • Reading
    • Wikipedia has a short article introducing event-driven programming.
    • Sets and Dictionaries are covered in Chapter 8. Read Sections 1 and 2, and stop at 8.3.
Week 14
4/28
  • Monday
    • Back to the example on sets. Making the counting of unique words even faster!
    • Dictionaries. Dictionaries, like sets, are data structures: data organized in a specific way so as to make some problems easier to write, or faster to execute, or more memory efficient.
    • Playing with dictionaries in the console:
>>> dict = {}
>>> dict = { "apple":1, "pear":3, "banana":6 }
>>> dict
>>> dict[ "pear" ]
>>> dict[ "orange" ]
>>> dict[ "kiwi" ] = 12
>>> dict.keys()
>>> dict.values()
>>> dict.items()
>>> for key in dict:
             print( key )
>>> for key in dict:
             print( key, dict[key] )
>>> contacts = {}
>>> contacts[ "Marie" ] = "111 22 33"
>>> contacts[ "Alex" ] = "222 33 44"
>>> contacts[ "Francis" ] = "333 44 55"
>>> contacts.pop( "Alex" )
MagicHat.png
    • Find the frequency of occurrence of words in a sentence
    • Find the 10 most frequent words in James Joyce's Ulysses
    • Recursion
      • A simple first example: factorials: the mathematical expression, and its version in Python.
      • Wrapping text recursively.
      • The towers of hanoi



AnimatedTowersOfHanoi.gif



  • Friday:

Final Take-Home EXAM


  • Reading
    • Dictionaries and sets are covered in Chapter 8. Section 8.3 is especially interesting.
    • Recursion is covered in Chapter 11. Read up to, but not including, Section 5.


Links and Resources


Map of Smith College

Full Map


SmithMap2.jpg


Reduced Map


SmithMapSmall.gif


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.
#

from graphics111 import *
import tkinter as tk

MAXWIDTH  = 800
MAXHEIGHT = 600


# ========================================================
#                       Main Program
# ========================================================
def main():
    gifFileName = "SmithMapSmall.gif"
    # open the window and get access to its canvas
    win = 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
#

from graphics111 import *

MAXWIDTH = 800
MAXHEIGHT = 800

def mouseEvent( win, canvas, x, y ):
    global menu
    
    button = menu.buttonClicked( x, y )
    
    if button == None:
        return
    
    if button == "LeftArrow":
        return
    
    if button == "RightArrow":
        return
    
    if button == "Minus":
        return
    
    if button == "Plus":
        return    


# ========================================================
#                       Main Program
# ========================================================
def main():
    global menu
    
    # open the window and get access to its canvas
    win = GraphicsWindow(MAXWIDTH, MAXHEIGHT)
    canvas = win.canvas()
    canvas.setCallbackFunction( mouseEvent )
    
    # add a menu to the window
    menu = 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

Linux


Misc


  • If you decide to work in pairs for the homework assignments, you need to follow the protocol for 'pair programming' as discussed in this article.
  • All the programs of Zelle's Python textbook


Software


  • Using SSH on Windows, Linux, or on a Mac with OS X


Class Videos


(The tables below were generated by this Python program.)

http://img.youtube.com/vi/YF9dxRkY4E8/mqdefault.jpg
CSC111 For-Loop exercises -- Exercise #5

http://img.youtube.com/vi/TNfI1tO70CE/mqdefault.jpg
CSC111 For Loop Exercises -- Exercise #4

http://img.youtube.com/vi/1VXPBeYBiuo/mqdefault.jpg
CSC111 For-Loop Exercises -- Exercise #3

http://img.youtube.com/vi/y1dv69bSSwk/mqdefault.jpg
CSC111 For-Loop Exercises -- Exercise #2

http://img.youtube.com/vi/_FZEwCOyQvA/mqdefault.jpg
CSC111 For-Loop Exercises: Solution for Exercise #1

http://img.youtube.com/vi/P1Myggumnso/mqdefault.jpg
CSC111 -- Using PythonTutor

http://img.youtube.com/vi/ELRMtELi0zE/mqdefault.jpg
Running Python Programs from the Command Line (Mac)

http://img.youtube.com/vi/6x2qtLrQdqU/mqdefault.jpg
Python on the command line in Windows

http://img.youtube.com/vi/1FomulmEjuk/mqdefault.jpg
CSC111 Intro to Lab 3

http://img.youtube.com/vi/TU2zzMM7v4A/mqdefault.jpg
CSC111 Notes on Homework 1 2014

http://img.youtube.com/vi/OCRvN0NJlHg/mqdefault.jpg
Comments for CSC111 TAs on Homework 1

http://img.youtube.com/vi/qwEDoAGB3NE/mqdefault.jpg
CSC111 Comments on Homework 2

http://img.youtube.com/vi/TgZxW6w6w8c/mqdefault.jpg
CSC111 Comments on Lab #1

http://img.youtube.com/vi/bjVO2MZroUU/mqdefault.jpg
CSC111 Spring 2014: Finding the Class Web Page









Back To Main Page