Ask Question
27 February, 00:21

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

+5
Answers (1)
  1. 27 February, 04:14
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers