Ask Question
23 September, 01:25

Using your text editor, write the function sumSquares (aList). The function takes a list as an input and returns (not prints) the sum of the squares of the all the numbers which absolute value is divisible by 3. If an element in the list is not a number, the function should ignore the value and continue. When the function receives an input that is not a list, code should return the keyword None (not the string 'None'). Hints: review the type () or isinstance () methods

+2
Answers (1)
  1. 23 September, 01:43
    0
    We have the Python code below with appropriate comments

    Explanation:

    #defining the function for use

    def sumSquares (aList):

    #checking if element in list is not in number as an error

    if type (aList) is not list:

    return 'error'

    sum = 0

    for x in aList:

    #checking if in list and is

    #divisible by 3

    if type (x) in [int, float] and x % 3 = = 0:

    #squares of number x is x*x

    # + = is an updating syntax that represents

    #the sum of the squares

    sum + = x*x

    #returning the sum, not printing

    return sum

    Sample test cases

    print (sumSquares (5))

    print (sumSquares ('5'))

    print (sumSquares (6.15))

    print (sumSquares ([1, 5, - 3, 5, 9, 8, 4]))

    print (sumSquares (['3', 5, - 3, 5, 9.0, 8, 4, 'Hello']))

    NOTE: Use in your code and view the result
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Using your text editor, write the function sumSquares (aList). The function takes a list as an input and returns (not prints) the sum of ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers