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
Answered by Brodie M. Python tutor

1337 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Write a function that checks whether a number is prime or not.


What would output this code? print(hello world)


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning