Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create these functions in list _ functions.py . Write a function squares ( n ) that returns a list of all the perfect squares from

Create these functions in list_functions.py.Write a function squares(n) that returns a list of all the perfect squares from 1 to n2. So, squares(5) should build the list [1,4,9,16,25], and return it. In your function, start with an empty list ([]) and use the .append method in a loop to add successive squares to the list.Create a function even_only that takes a list of numbers as an argument. It should return a list that consists of all the elements from the argument that are even numbers. For example, even_only([2,4,5,9,10,12]) should return [2,4,10,12] and even_only(squares(10)) should return [4,16,36,64,100].Suggestion: Create an empty list for the result. Iterate though the items in the argument list. As you go, if an item is even, add it to the result list. At the end, return the result list.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions