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

1036 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Create a program that generates prime numbers between two integer boundareis


Create a python code to sum the number from 1 to 10.


[Exam style] Python is an interpreted language. Explain what this means and how interpreted languages differ from compiled languages.


Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences