CSC 221: Introduction to Programming
Test 2 Review


Mon, Nov 6
  • As with Test 1, the test will contain extra points (e.g., 52 out of 50).
  • As with Test 1, the test will include a variety of questions (e.g., TRUE/FALSE, short answer, trace/modify code).
  • As with Test 1, the test will be in-person, online (bring laptop), closed book/notes.
Study advice
  • reflect on your Test 1 performance
  • review online lecture notes (if not mentioned in class, won't be on test)
  • review online text
  • look over quizzes, homework assignments
  • reference other sources for examples, different perspectives
Course Material   
TEST 1 MATERIAL
Iteration on sequences
    sequence types: range, string, list, tuple
      returning a sequence, assigning a sequence
      in operator
    for-in loop, loop variable
    printing using f-strings
    input files
      open, read, readlines, close  
Sequences and strings
    common operations/functions: 
      +, *, len
      indexing via [i]
      slicing via [s:e] and [s:e:n]
    traversal
      can traverse using 'for X in SEQ: ... X ...'
      can traverse using 'for i in range(len(SEQ)): ... SEQ[i] ...'
      can test membership using 'X in SEQ' and 'X not in SEQ'
    each type of sequence has its own type-specific methods
        unlike functions, called as SEQ.METHOD(INPUTS)  
    strings
      sequence of characters, immutable
      methods
        type related: isalpha, isupper, islower, isspace
        case related: capitalize, upper, lower
        format related: center, rjust, strip, rstrip
        search related: count, find, replace
      traversing a string
        by character vs. by index
        building a copy of a string (accumulator pattern)
      examples: palindrome, rotation, cipher
Lists
    sequence of arbitrary items, mutable
    methods
      search related: count, index
      order related: sorted, reversed, sort, reverse
      updates: append, extend, insert, remove
    strings to lists
      string split method, splitting user input into words/numbers
    building lists
      building a list (accumulator pattern), lists of counters
      examples: dice stats, averaging, acronym 
Lists and files
    reading in and storing file contents
      strip to remove line breaks
    large file of words
      examples: isWord, wordStats, anagrams
    try-except to catch and handle errors
    efficiency: sequential vs. binary search, multiple passes
Nested lists and dictionaries
    simple vs. complex data, records as lists, lists of lists
      reading from a csv file, building a list of lists
      searching based on different fields, within fields
    data files & tasks
      state capitals: getCapital, getGPS, quiz
      HDI stats: getHDI, getRank, displayAllAbove
      tweets: inTweets, inMentions, mostLiked, onDay, allDays
    dictionaries
      dictionaries store key:value pairs
        create using {}, access using []
        any type of value can be the index (e.g., string)
      examples
        manyDecisions, allDays, wordCounts, anagrams