Learning Objectives
Through readings, lecture and labs, it is expected that you are doing work and seeking help to keep pace with the below objectives:
- Accumulator pattern
- You should be able to:
- Trace the execution of code that uses accumulation
- Recognize simple examples of problems that use this pattern
- Write code to solve these problems
- Our graphics library
- You should be comfortable with:
- Writing programs that display a graphics window.
- Drawing colored circles and rectangles in the graphics window.
- Calculating the desired positions of circles and rectangles.
- Conditionals (
if
statements) - You should be comfortable with:
- Tracing the execution of programs using
if
,elif
,else
- Computing the values of Boolean expressions (expressions that evaluate to
True
orFalse
). - Writing programs that use these constructs.
- Tracing the execution of programs using
Required Reading
Supplemental Materials
We all need alternative presentations of the concepts from time to time. The following resources are optional. If something seems unclear after class, or the pratice questions seem hard for you, then explore these topics more using the resources below.
- Accumulator pattern
-
- Video: using a loop to keep a running total (i.e. an accumulation)
- Zelle, Sections 2.7, 3.3, 8.1
- Miller and Ranum, Newton's Method. This is a use of loops for a more complex application, called Newton's method. This is not a simple example, but its a good test of your understanding if you are feeling comfortable with the simpler examples we've seen.
- Our graphics library
-
- CS115 Graphics Tutorial
- Zelle, Sections 4.1–4.4
- Conditionals (
if
statements) -
- CS Circles lesson on if-statements
- CS Circles lesson on
else
,and
,or
,not
- Zelle, Sections 7.1–7.3
- Zelle, Sections 7.5
Practice
For all these exercises, I recommend you try them on paper and then test them out with PythonTutor.Exercise 1
Write what this code produces, exactly. Be very careful with whitespace and the newlines.
seaw = 'SeaWolves' print('Go', seaw, end='!\n!') print(seaw + ' Rock')
Exercise 2
Write what this code produces, exactly. Be very careful with whitespace and the newlines.
k = 0 for i in range (1 , 10, 2): print(i) k = k + i print (k)
Exercise 3
Write a piece of code that produces the following input/output behavior. Text that is italics and underlined are user input.
Enter an integer: 100 Sum of squares of numbers 1--100 is: 338350Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).