-
Notifications
You must be signed in to change notification settings - Fork 271
/
powers.py
44 lines (33 loc) · 1.29 KB
/
powers.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
42
43
44
def powers(N, p):
"""
Return the first N powers of p. For example:
powers(5, 2) --> [1, 2, 4, 8, 16]
powers(5, 4) --> [1, 4, 16, 64, 256]
Input:
N: number of powers to return
p: base that we are raising to the given powers
Returns: an array consisting of powers of p
"""
# YOUR CODE HERE
# Replace None with an appropriate return value
return None
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
import numpy as np
sys.path.append('../')
import test_utils as utils
def test_powers():
for p in [1, 2, 4]:
for N in [1, 2, 5, 10]:
recreate_msg = utils.gen_recreate_msg('powers', N, p)
result = powers(N, p)
utils.check_none(result, recreate_msg)
utils.check_is_ndarray(result, recreate_msg)
utils.check_array_equal(result,
np.array([p**i for i in range(N)]),
recreate_msg)