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 ▸

Explain how python programs are structured and give an example of how methods are initiated


What is the difference between a for and a while loop?


Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.


What is the difference between a cycle "if" and "while"?