logo CodeStepByStep logo

print_elements

Language/Type: Python lists

Write a function named print_elements that accepts a list of integers as a parameter and uses a for loop to print each element of a list named data that contains five integers. If the list contains the elements [14, 5, 27, -3, 2598], then your code should produce the following output:

element [ 0 ] is 14
element [ 1 ] is 5
element [ 2 ] is 27
element [ 3 ] is -3
element [ 4 ] is 2598

Once your code works for the list of size 5, generalize the code so that it works for a list of any length.

Bare code: Write a fragment of Python code as described, without any class or function/method heading around your code.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.