# 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

#address="dfdsfdsfsdfsdfdfsdfdsf"
address_count=counter(address)
print(address_count)```

### 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

address_count=counter(address)
print(address_count.values())
highest = max(address_count.values())
for key in address_count:
if address_count.get(key)==highest:
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-x)^2)+((y-x)^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*n_neighbors)
print (x[-1]*n_neighbors)
x = [x]*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>
Topic revision: r3 - 2018-06-04 - JimSkon    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