# EdX code

### HW 1

```def counter(s):
# Create your function here!
count_letters = {}
#write your code here!
for c in s:
if c in string.ascii_letters:
if c in count_letters.keys():
count_letters.update({c:count_letters.get(c)+1})
else:
count_letters.update({c:1})
return count_letters

### HW 2

```import string
def counter(s):
# Create your function here!
count_letters = {}
#write your code here!
for c in s:
if c in string.ascii_letters:
if c in count_letters.keys():
count_letters.update({c:count_letters.get(c)+1})
else:
count_letters.update({c:1})
return count_letters

for key in address_count:
most = key
break

most_frequent_letter=most
print(most_frequent_letter)```

### HW 3

```import math

def distance(x, y):
print(x)
print(y)
return math.sqrt(((y[0]-x[0])^2)+((y[1]-x[1])^2))

a = (0,0)
b = (1,1)
print(distance(a,b))
```
</sticky>

### HW4

```R = 10000
x = []
inside = []
for i in range(R):
point = [rand(), rand()]
print(in_circle(point))
x.append(point)
inside.append(in_circle(point))
# append inside here!

print(sum(inside) / R)
```
</sticky>

### HW 5

```import random

random.seed(1)

def moving_window_average(x, n_neighbors=1):
n = len(x)
result = []
width = n_neighbors*2 + 1
print (x[0]*n_neighbors)
print (x[-1]*n_neighbors)
x = [x[0]]*n_neighbors + x + [x[-1]]*n_neighbors
for i in range(n):
total = sum(x[i:i+width])
ave = total/width
result.append(ave)
return result

# To complete the function,
# return a list of the mean of values from i to i+width for all values i from 0 to n-1.

x=[0,10,5,3,1,5]
print(moving_window_average(x, 1))```
</sticky>

</sticky>

</sticky>

</sticky>

</sticky>

</sticky>

</sticky>

</sticky>

</sticky>

### HW 1

</sticky>
Edit | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | More topic actions
Topic revision: r3 - 2018-06-04 - JimSkon

 Home Main Web P View Edit Account
Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback