CPSC 1301 - Computer Science I NOTES - Fall 2012

Date

Topics

August 12

August 14

  • Q&A
  • Chapter 1: 1.1-1.3: Computers, Programming
  • Intro to Python and IDLE

August 16

August 19

  • Q&A
  • Python 4. - Input function and variables

August 21

August 23

  • Q&A
  • Python 6. - decision statements

August 25

  • Q&A
  • Python 6. - Decisions and loops

August 28

  • Q&A
  • Python 7. – Debugging
  • QUIZ 2 (python 5-6)

Sept. 2

LABOR DAY

Sept. 4

  • Q&A
  • Python 8. - Defining functions
    • def must be followed by the function name and the parenthesized list of formal parameters.
    • The statements that form the body of the function start at the next line, and must be indented.
    • The return statement returns with a value from a function.
    • return without an expression argument returns None.
    • Falling off the end of a function also returns None.
  • Examples
    • def fib(n): # write Fibonacci series up to n
      """Print a Fibonacci series up to n."""
        a, b = 0, 1
        while a < n:
          print(a, end=' ')
          a, b = b, a+b
        print()
    • def big3(a, b, c): #returns largest of 3 numbers
      """returns the largest of 3 numbers"""
        if (a >= b):
          if (a >= c):
            large = a
          else:
            large = c
        elif (b >= c):
          large = b
        else:
        large = c
        return large

Sept. 6

  • Q&A
  • Python 9. - Defining functions

Sept. 9

  • Q&A
  • Python 10. - Lists
    • A list is an ordered, sequential collection of zero or more data items
    • A list is written as comma-delimited values enclosed in square brackets - e.g. [15, 23, -5, 7], ['spam', 'flying', 'circus'], [18, 'virus', 'eggs', '23, -56.5]
    • Like string indices, list indices start at 0, and lists can be sliced, concatenated and so on:
      >>> a = ['spam', 'eggs', 100, 1234]
      >>> a[0]
      'spam'
      >>> a[3]
      1234
      >>> a[:2] + ['bacon', 2*2]
      ['spam', 'eggs', 'bacon', 4]
      >>> 3*a[:3] + ['Boo!']
      ['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']
    • Unlike strings, which are immutable, it is possible to change individual elements of a list:
      >>> a
      ['spam', 'eggs', 100, 1234]
      >>> a[2] = a[2] + 23
      >>> a
      ['spam', 'eggs', 123, 1234]
    • The built-in function len() also applies to lists
  • Quiz 3 (Python 8-9)

Sept. 11

  • Q&A
  • Python 10. - Lists Functions

list.append(x)

Add an item to the end of the list; equivalent to a[len(a):] = [x].

list.count(x)

Return the number of times x appears in the list.

list.extend(L)

Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.

list.index(x)

Return the index in the list of the first item whose value is x. It is an error if there is no such item.

list.insert(i, x)

Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x).

list.pop([i])

Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position.

list.remove(x)

Remove the first item from the list whose value is x. It is an error if there is no such item.

list.reverse()

Reverse the elements of the list, in place.

list.sort()

Sort the items of the list, in place.

Sept. 13

  • Q&A
  • Python 11. - for loops
    • for identifer in sequence: (Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. )
    • ex.:
      actors = ['Idle', 'Clease', 'Palin"] for actor in actors:     print ('Hello my name is', actor)
    • ex2: for count in range(1,5):     print (count)
    • ex3: for count in range(5):     print (count)
    • ex4: for count in range(1,5,2):     print (count)

Sept. 13

  • Q&A
  • Python 17. - File I/O
    • Opening / Closing text files in Python

Function name

Use

Explanation

open

open(filename, 'r')

Open a file called filename and use it for reading

open

open(filename, 'w')

Open a file called filename and use it for writing

close

filevariable.close()

close file (file use is complete

    • Reading / Writing text files in Python

Function name

Use

Explanation

read

f.read()

returns a single character value

read

f.read(n)

returns no more than n character values

readline

f.readline()

return the next line of input

readlines

f.readlines()

returns all the file as a list

write

f.write(s)

write string s to file

writelines

f.writelines(lst)

write list lst to file

    • Sample Programs with files:
      • read_write.py - writes to a file and then reads from that file
      • spam.py - reads a text file and echo prints it
      • spamSwap.py - reads a text file and swaps cases
      • spanReverse.py - reads a text file and prints it in reverse
      • spamReverse.py - reads a text file, sorts the lines of text, and then writes it to another file
      • monty.py reads a file with first and last names and separates them
      • montypython.py reads a file with first and last names, stores them in separate lists, and prints the list of last names
  • Quiz 4 (Python 10-11)

Sept. 16

Java programming; algorithms

Sept. 18

data types, variables, assignment statements

Sept. 20

Sept. 23

Objects, Classes, Methods, API

Sept. 25

Objects, Classes, Methods, API, Test Program

Sept. 27

continue History;Graphics; QUIZ 6: chapter 1,2

Sept. 30

3.1-3.3 Implementing Classes

Oct. 2

REVIEW

Oct. 4

MIDTERM EXAM

Oct. 9

3.3-3.5  Implementing Classes, UNIT testing

Oct. 11

3.5-3.9 Implementing Classes, Local Variables, Implicit Parameters, Shape Classes, Graphics

Information Assurance

Oct. 14

QUIZ 7 (ch.3)

4.1-4.2 numbers, constants, CashRegister.java

Oct. 16

4.3-4.4 Arithmetic/math operators & functions

Strings

Oct. 18

4.5-4.6 Strings, Input

Security, Reliability (Floating Point Bug)

Oct. 21

QUIZ 8 (ch.4)

5.1-5.2

If statement, Comparing

Oct. 23

5.2-5.4

Comparing, Multiple alternatives

Oct. 25

5.3-5.5

Multiple alternatives, Boolean Expressions

Oct. 28

Quiz 9 (ch. 5)

6.1-6.2

While, for loops

Oct. 30

6.2-6.4

While, for loops Nested loops

Nov. 1

6.4-6.6

Boolean expressions, debugger

Nov. 4

Quiz 10 (ch. 6)

Chapter 7: 7.1-7.2

ArrayLists, for-each

Nov. 6

Chapter 7: 7.1-7.2

ArrayLists, for-each

Nov. 8

Chapter 7: 7.1-7.3

Arrays, ArrayLists, for-each

Nov. 11

Chapter 7: 7.3-7.4

Arrays, wrappers

Nov. 13

Chapter 7: 7.4

Arrays, wrappers

Nov. 15

Chapter 7: 7.5-7.6

Array algorithms

Nov. 18

Chapter 7: 7.5-7.6

Array algorithms

Nov. 20

2-D arrays

 

Nov. 22

2-D arrays

 

Nov. 25

regression testing

Quiz 11 (ch. 7)

Nov. 27

THANKSGIVING

Nov. 29

THANKSGIVING

Dec. 2

REVIEW (Python, Java Chapters 1-7)

 

 

 

 

Academic Dishonesty/Academic Misconduct Policy


Back to Class List Page

written by Wayne Summers summers_wayne@ColumbusState.edu
last update: 2/20/2012