-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw1.py
41 lines (27 loc) · 809 Bytes
/
hw1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Avery Cunningham
Homework 1
2/17/2021
I pledge my honor that I have abided by the Stevens Honor System
'''
from cs115 import *
def mult(x, y):
"""Returns the product of x and y"""
return x * y
def add(x, y):
"""Returns the sum of x and y"""
return x + y
def factorial(n):
"""Takes a positive integer n and returns its factorial (n!)"""
return reduce(mult, range(1, n+1))
def mean(L):
"""Returns the numerical average of the values in the list L"""
return float(reduce(add, L)/len(L))
def divides(n):
"""Returns the div function which takes n mod k"""
def div(k):
return n % k == 0
return div
def prime(n):
"""Returns true if integer n is prime, and false if it is coprime"""
return sum(map(divides(n), range(2, n))) == 0 and n > 1