sgoodspeed/CS112-Spring2012 — comment on commit 36223c8d5a0085f4ec11501d418e7cbb0eb76973
File:  line 0
By alecgoebel:

Homework 4
============

| **Part** | **Points** |
|--------|------|
| base | 1 |
| advanced | 0.75 |
| **Total** | **1.75 pts** |

# Section 1: If

**2-3)** Not a big deal (aka no points lost) but if I phrase things as "add four" or "double it", I mean to modify the variable. So `n *= 2`, not just `n*2`.

**4)** Your way of doing it is fine, but you can take advantage of the order of the if statements here and go the other direction.

```python
if grade >= 90:
print "4. A"
elif grade >= 80:
print "4. B"
# ...snip...
```

## Section 2: While

**3)** Your method will work this way, but I was hoping you'd use variables.

```python
num = int(raw_input("3. Countdown from: "))

if num % 3 == 0:
step = 3
elif num % 2 == 0:
step = 2
else:
step = 1

while num >= 0:
print num
num -= step
```

## Section 3: Lists

**4)** You inserted 7 as the third element, not replaced. `nums[2] = 7`

**5)** Extends defintely works here. Alternatively you can use `nums += nums2`.

**9)** Most got this one wrong since it was so vaguely worded. I mean a list which only contained the second element, or `nums[1:2]`.

## Section 4: For

**1)** Yes, I too know of the `sum` function, but I as looking for you guys to write it yourself.

```python
total = 0
for n in nums:
total += n
```

**2)** Your code is commented out but it looks close

**3)** Your code works here, but you are using ints instead of just bools.

```python
evenCheck = True
for i in nums:
if i%2 != 0:
evenCheck = False

if evenCheck:
print "3. All even"
else:
print "3. Some odd"
```

Alternatively, now that you know list comprehensions.

```python
alleven = all(i%2 == 0 for i in nums)
```

**4)** So here you had an empty list of numbers, then took a list of all the odd numbers and appended them to the empty list one at a time. `oddHundred` is the same thing as `range(1,101,2)`.

**5)** Very complicated solution, but I guess it works. It can more simply be written like this:

```python
for i in range(len(nums)):
nums[i] *= i
```

## Cake or Death

First off, `int` of a number is the same things as just the number:

```python
cake = int(6)
choice = (int(0))

# same as
cake = 6
choice = 0
```

Second, you code works and is correct. The only thing is that I was looking to enter "cake" or "death", not "1" or "2". Otherwise, well done overall.

## Checkerboard
Good attempt but not quite. It doesn't actually alternate and the boards are twice as big as they should be and one row to wide. Here is a "clever" solution we mentioned in class.

```python
width = int(raw_input("Width: "))
height = int(raw_input(Height: "))

row = "#-" * width

for i in range(height):
start = i % 2
end = width + start
print row[start:end]
```