Question: (using python) Recall that a for loop has the following structure: for VARIABLE in COLLECTION: #loop body one or more statements Lets start with an

(using python)

Recall that a for loop has the following structure:

for VARIABLE in COLLECTION: #loop body one or more statements 

Lets start with an easy for loop example to remind us how to use a for loop.

fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) 

This code goes through the list to print out apple, banana, and cherry.

Now, use this code as a basis for a function print_list_index, which would produce the following output:

apple is at index 0 banana is at index 1 cherry is at index 2 

Below is the template for the function definition.

Test your code by running it with the following examples:

>>> fruits = ["apple", "banana", "cherry"] >>> print_list_index(fruits) apple is at index 0 banana is at index 1 cherry is at index 2 >>> print_list_index(["A", "B", "C"]) A is at index 0 B is at index 1 C is at index 2

----------------------------------------------------------------------------------------

given code:

def print_list_index( aList ): """ Given an input list aList, display " is at index " for each item in the list. """ pass # TODO: replace with the proper output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!