SquareEachnums function nums is a list of numbers The functi

SquareEach(nums) function. nums is a list of numbers. The function modifies the list by squaring each entry. The function returns None. Test your solution using the following test() function: When correctly implemented, the test() function will print [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169., 196)

Solution

# square each number in list
def squareEach(nums):
   # loop thourgh nums
   for i in range(len(nums)):
       # square each number in list
       nums[i] = nums[i]**2

def test():
   nums = list(range(15))
   squareEach(nums)
   print(nums)
test()

\"\"\"
sample output

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196]

\"\"\"

 SquareEach(nums) function. nums is a list of numbers. The function modifies the list by squaring each entry. The function returns None. Test your solution usin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site