# CS21: Quiz 2 Topics

### In addition to all concepts from Quiz 1

#### You should be able to define the following terms:

• data types: boolean, list
• branching and looping
• the accumulator design pattern
• slicing and indexing

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

• basic arithmetic expressions using +, -, *, /, **, %
• conversion between the int, float, and str types
• reading in strings using raw_input()
• the empty string ""
• string concatenation with +, repetition with *
• string and list indexing with []
• string and list slicing with [:]
• for loops over strings and lists
• len()
• tracing a program (show the variable values and output)
• if, if/else, if/elif/else
• relational operators <, <=, ==, >, >=, !=
• boolean operators and, or, and not
• random library functions: randrange(), choice()
• nested statements (an if/else inside a loop)
• print formatting

#### Practice problems:

1. Show the value and type of each of the following, given these assignments:
```x = 5
y = 13
ls = ["pony", "zebra", "donkey", "unicorn"]
s = "we love computer science"

x < 10 and y < 10

x < 10 or y < 10

x < 10 and x > 0

x > 10 or x < 0

range(1,100,10)

(5/y) > 7.0

len(s) >= 10

range(len(ls))

s[8:12] + s[17:20]

len(ls[2])

```
2. Trace the following program and show it's output:
```  x = 3
print 0,x
for i in range(1,6):
if x % 2 == 0:
x = x / 2
else:
x = (3*x+1)/2
print i,x
```
3. Write a program that accepts 5 grades (0-100) from the user and displays the average of all 5 grades, as well as the corresponding letter grade for each input (where A is >= 90, B is 80-89, etc):
```grade: 96
that's an A