# CS21: Quiz 3 Study Guide

### In addition to the concepts from Quiz 1 and Quiz 2,

#### You should understand and/or be able to use the following Python concepts:

• definite (for) loop
• indefinite (while) loop
• random library functions: randrange(start, stop), choice(list)
• object oriented programming
• graphics objects
• instance of a graphics object
• data and methods of an object
• pixels
• animation, sleep
• lists and strings as objects
• list and string methods (e.g., strip(), split(), upper(), append(), index())
• python in (and not in) operator used on lists and strings

#### You should understand how to make instances of the following graphics objects and how to use their methods:

• GraphWin: setBackground(), getMouse()
• Point: getX(), getY()
• Line: getP1(), getP2()
• Rectangle: getP1(), getP2()
• Graphical objects can also: draw(window), undraw(), move(dx, dy), setFill(color)
• also color_rgb(r,g,b)

#### Practice problems:

1. Write a program that asks the user for a positive integer, n, and then calculates and displays the sum of all numbers from 1 to n. For example, if the user enters 5, the program calculates 1 + 2 + 3 + 4 + 5

2. Write a program that reads in student grades from the user until the user enters a -1. After reading in the -1, the program should compute and display the average grade:
```Please enter your grades below.
Enter a -1 when you are all done...

The average of those 5 grades is 85.000
```
3. Write a program that asks the user for a number (positive integer, n), and then asks the user to click the mouse n times, anywhere in a graphics window, each time drawing a small red circle where the user clicked.

4. What would be the TYPE of each of these?
```   p = Point(100,200)             type of p?
c = Circle(p, 5)               type of c?
x = c.getRadius()              type of x?
c2 = c.clone()                 type of c2?
L = [c, c2]                    type of L?
m = L                       type of m?
y = L.getCenter().getY()    type of y?

```
5. Given the assignments for S and L, what is the value and type of each expression?
```L = ["There are", "many", "like it,", "but this one", "is mine."]
S = "abcdefg"

len(L)

len(S)

range(len(S))

L.split()

L.split("h")

"a" in L

"ABC" in S
```