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 "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
