CSC 221: Introduction to Programming
Test 2 Review


Thu, Nov 15
  • As with Test 1, the test will contain extra points (e.g., 53 out of 50).
  • As with Test 1, the test will include a variety of questions (e.g., TRUE/FALSE, short answer, trace/modify code).
Study advice
  • 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
	
Sequences
  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, char-by-char
    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, item by item
      list comprehensions, conditional comprehensions
    examples: dice stats, averaging, acronym
    big data
      e.g., text files --> file stats, literary fingerprints
      e.g., Trump tweets --> average length, word/char frequencies
      e.g., dictionary --> word stats, find anagrams
      e.g., Trump metadata --> percent retweets, most favorited, day stats
    
User Interaction
  input/output
    input: numbers must be converted (int, float)
    print: automatically separates values with spaces, adds newline
           can avoid spacing using concatenation, e.g.,  str(percent)+"%"
           can avoid new line using end=""
  files
    open a file using open function
      with open(filename, "r") as infile:
      with open(filename, "w") as outfile:
    file input methods:
      read() vs. read(1) vs. readline()
      can use string split method to structure complex data
    file output methods
      write(), use "\n" for a line break