Grug16/CS112-Spring2012 — comment on commit b5fda6157a2b200f3fee91a4541dec9f85dff11a
File:  line 0
By alecgoebel:

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

| **Part** | **Points** |
|--------|------|
| base | 1 |
| advanced | 0.75 |
| interesting approaches | 0.25 |
| **Total** | **2 pts** |

Overall, well done on this homework. I know you were having github issues so I am not marking down as late for this (especially since I am only now getting to grading it.)

One quick comment about all of your code is that in python, if statements don't require parentheses around them. They will work even if they are there.

## Section 1: if statements

**2)** You got this one wrong. First, it doubles if n is even not odd. It also doesn't double n, just but creates a new variable. Otherwise this section is right.

```python
# should be
if n % 2 == 1:
n *= n
print "2.", n
```

## Section 2: While
This section looks good. You could more succinctly write your looping raw_inputs but since the input string changes, this way is correct.

## Section 3: Lists

**3)** This works but you can write it more cleanly with `nums.pop()` which removes the last element. You can use `nums.pop(index)` if you want to remove a specific element.

**6)** This won't work properly since `nums_copy` is not a copy but a reference. Use `nums[:]` to make a copy of the array (also can be read as "a slice of everything").

**9)** The wording was vague, but I was looking for a list of the second element. `nums[1:2]` returns a list with just the second element in it.

## Section 4: For

**3)** This works, but has a bit of unnecessary code.

```python
# cleaner
for x in nums:
if x % 2 != 0:
only_even = False
```

**4)** That method will work. As will your second method. What I was looking for was just `range(1,100,2)`

**5)** You were right with the crude solution. Plus it won't work if there are duplicate numbers. A simpler method:

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

## Cake or Death
I have nothing to comment on. You did this portion correctly. Only possible room for improvement is making sure the input is lower case with `answer = raw_input("cake or death? ").lower()`

## Checkerboard
I wasn't sure this one worked at first. It seems it doesn't properly "checker" if the width is odd. Your algorithm looks reasonable if not slightly complicated. This seems to be because you just alternate characters and inserting line breaks. Instead, you should build each line based on it's index. Either way, good attempt and full points.

I believe we went over this in class, but here is a solution. I did not expect you guys to come up with this algorithm.

```python
width = int(raw_input("Enter Width: "))
height = int(raw_input("Enter Height: "))
chars = "#-" * width

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