Write a function s(n) that will return a list of the first n squares.

def s(n): ans=[] #This variable stores the list we will return. for i in range(n): #This is a for loop that will iterate n times. ans.append((i+1)**2) #This adds the (i+1)th square to the list, because range() is 0-indexed. return ans

BM

Related Python Mentoring answers

All answers ▸

Manually implement a function that finds the smallest value in a list of integers and print it.


Write a recursive function to return the nth Fibonacci number in Python


What does __init__ mean?


Write a short program to print all the even numbers 1 to 100