CSC 221: Introduction to Programming
Fall 2012
- To develop problem solving and programming skills to enable the student to design solutions to non-trivial problems and implement those solutions in Python.
- To master the fundamental programming constructs of Python, including variables, expressions, functions, control structures, and lists.
- To build a foundation for more advanced programming techniques, including object-oriented design and the use of standard data structures (as taught in CSC 222).
GENERAL KNOWLEDGE
overview & history: hardware vs. software, technology generations, ...
problem-solving skills, critical thinking skills, communiation skills
SCRATCH PROGRAMMING
simple, visual introduction to programming concepts
actions (e.g., move), conditionals, loops, event-handlers, variables
simple object interaction via sensing and broadcasts
introduction to object-oriented concepts
sprites = objects, sprite properties = fields, script blocks = methods
PYTHON LANGUAGE FEATURES
variables:
basic data types: numbers, strings, Booleans
naming conventions, assignment statements, expressions
functions
def, parameters, return statements, doc strings
built-in functions (print, abs, max, min), importing modules (random, math)
conditional execution
if statement, Boolean operators (<, <=, >, >=, ==, !=, and or, not)
if (1-way), if-else (2-way), cascading if-else, elif (multi-way)
repetition
for loops, counter/range-driven
while loops, condition-driven
sequences
common operations/functions: +, *, len, indexing, slicing
traversal: by item, by index
strings (sequences of characters, immutable)
methods: isalpha, capitalize, upper, strip, find, replace, ...
examples: palindrome, Caesar cipher, Pig Latin
lists (sequences of arbitrary items, mutable)
methods: count, index, sort, append, extend, insert, remove, ...
list comprehensions
examples: list of words, row of cards, 2-D grid of pixels
classes/objects
class definition, fields, methods, self
special methods: __init__, __str__
examples: Die, DeckOfCards, RowOfCards, Image
PROGRAMMING TECHNIQUES
conditionals for alternatives
e.g., recognize doubles, recognize a vowel, distinguish Skip-3 commands
loops for repetition (conditional while loops, range-driven for loops)
counters & sums for collecting data
e.g., roll dice until doubles, count number of vowels, play until "quit"
String traversal/concatenation for manipulating text
e.g., construct acronym, encode a message, get avg word length
input for user input; read/readline/write for files
e.g., interactive Skip-3, reading text from a file & splitting into words
lists for storing and accessing arbitrary data
e.g., words from a line of text, cards in a deck, pixels in an image
object-oriented design
classes model real-world entities; objects are instances of those classes
fields maintain state of an object; methods implement behaviors
e.g., RowOfCards models a row of cards
field (list of cards), methods (addAtEnd, moveCard, numCards, ...)