Class 41 — December 6
I know that you know that
Programming basics — You achieved this semester — Bask in the success
Look both ways
Agenda
- Be chrestohistorical
Thanks to the undergraduate TAs for making the course successful
Vienna Donnelly Hallie Khoung Brandon Nielsen Ryan Green Hao Liu Jeanine Seaman Nadia Hassan Rachel McNamara Jacob St. Martin Ann Hoang Monica Nguyen Sophia Rogers
Want to be a TA for CS 1112
- Departmental application
Test problem solving process
- Read entire problem before coding
- Think about solution stratgey before coding
- Is a choice being made?
- Likely need an
if-elif-else
statement
- Is something be built? If so,
- Likely need an accumulator and a loop structure
- Initialize accumulator
total = 0
for summation
product = 1
for product
values = []
for list
- Loop to update accumulator
- Is a simple sequence just being examined? A loop is probably necessary unless there are built-in functions to assist (e.g.,
max()
,min()
, andlen()
)
for value in sequence :
...
- Are the elements of a simple sequence being modified? A
for i in range
loop is probably necessary
n = len( sequence )
for i in range( 0, n ( :
value = sequence[ i ]
...
sequence[ i ] = ...
- When is a nested loop necessary?
- Examining an image
for x in range( 0, width ) :
for y in range( 0, height ) :
spot = (x, y )
...
- Examining a dataset / table
for row in dataset :
for value in row :
...
Other patterns
- Examine and create dictionaries
- Convert a list of tuples into a dictionary
- Convert a list of two-element lists into a dictionary
- Examine a list with respect to a dictionary
- Examine a table
- Perform an accumulation
- Process a table on a row by row basis
- Convert cells from strings to numerics
- Check to see if all data cells in the table are of the same form
- Check to see if any data cells in the table are of the desired form
- Check to see if all rows in the table are of the same form
- Check to see if any rows in the table are of the desired form
- Photo manipulation
Realizations
- A variable has an identity and a type
- The value of a variable indicates where the object which it represents can be found
- Strings are immutable
- Converting string data to numeric data.
- To get a single integer value
nbr
from a single numeric representationv
nbr = int( v )
- To get a list of integer values
nbrs
from a list of numeric representations
nbrs = []
for v in s :
nbr = int( v )
nbrs.append( nbr )
- Python function usage
- A function invocation cannot change the identity of an argument
- All functions return a value either explicitly or implicitly. If there is no explicit return, None is returned.
Truisms
- The test will cummulative.
- Questions can require in part familiarity with
- Fundamental types; e.g.,
int
,float
, andstr
- Arithmetic operators; e.g.,
+
,-
,*
,**
,/
,//
, and%
- Identifiers, keywords, variables, objects, values, and references
- Logical and relational operators;
and
,or
,not
,==
,!=
,<
,>
,<=
, and>=
- Control constructs; e.g.,
if
,for
, andwhile
- Nested
for
constructs
- Random value manipulation
random.seed()
random.randrange()
random.choice()
- Builtin-in functions; e.g.,
print()
,input()
,int()
,float()
,str()
,max()
,min()
,len()
,type()
, andid()
- URLs and web files; e.g., numeric, text and CSV contents
- Ranges
- Data structures and their use:
list
,dict
, tuples, methods and slicing
- Functions, parameters, definitions, and invocations
- Colors and PIL Image
Final thought
- I say thanks to you — Your presence is a great gift — Brings me happiness
© 2019 Jim Cohoon | Resources from previous semesters are available. |