CoCalc Public Filessupport / 2019-10-20-204928.ipynb
Author: William A. Stein
Description: Jupyter notebook support/2015-06-04-141749-bokeh.ipynb
In [ ]:



# foo

bar

In [ ]:
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

Test your code from above here(0 points), ID: f72258
In [ ]:
# [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