Squaring all elements in a list

后端 未结 10 1179
一整个雨季
一整个雨季 2020-12-01 11:11

I am told to

Write a function, square(a), that takes an array, a, of numbers and returns an array containing each of the values of a squared.

At first, I ha

10条回答
  •  被撕碎了的回忆
    2020-12-01 11:42

    def square(a):
        squares = []
        for i in a:
            squares.append(i**2)
        return squares
    

    so how would i do the square of numbers from 1-20 using the above function

提交回复
热议问题