Skip to content

Instantly share code, notes, and snippets.

@edenau
Created February 9, 2020 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edenau/a25e86dfa6441351955aef530afbf9f1 to your computer and use it in GitHub Desktop.
Save edenau/a25e86dfa6441351955aef530afbf9f1 to your computer and use it in GitHub Desktop.
def sum_of_squares(nums):
"""
Compute the sum of squares of a list of numbers.
Args:
nums (`list` of `int` or `float`): A `list` of numbers.
Returns:
ans (`int` or `float`): Sum of squares of `nums`.
Raises:
AssertionError: If `nums` contain elements that are not floats nor ints.
"""
try:
ans = sum([x**2 for x in nums])
except:
raise AssertionError('Input should be a list of floats or ints.')
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment