Kernel: Python 3 (Anaconda 2019)
In [0]:
foo
bar
In [0]:
def squares(n): # modify function name and parameters """ Compute the squares of the numbers from 1 to n. [replace with function description] """ ### BEGIN SOLUTION # Put correct code here. This code is removed for the student version, but is used # to confirm that your tests are valid. if n < 1: raise ValueError("n must be at least 1") return [i**2 for i in range(1, n+1)] ### END SOLUTION
In [0]:
# [Modify the tests below for your own problem] # Check that squares returns the correct output for several inputs: from nose.tools import assert_equal assert_equal(squares(1), [1]) assert_equal(squares(2), [1, 4]) # Check that squares raises an error for invalid input: from nose.tools import assert_raises assert_raises(ValueError, squares, 0) assert_raises(ValueError, squares, -1) ### BEGIN HIDDEN TESTS # students will NOT see these extra tests assert_equal(squares(10), [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]) ### END HIDDEN TESTS