1. Take an integer as input: this is the total count of items to store in the list. 2. Loop for count times to get user inputs and append the input items to a list user_list. 3. Create a function print_list_index(), with my_list as a parameter. o Inside the function, loop over the my_list and print " is at index " 4. Call the function print_list_index() with user_list as an argument in your main program. Input 5 apple banana cherry mango pear Output apple is at index 0 banana is at index 1 cherry is at index 2 mango is at index 3 pear is at index 4

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Print list indices and items on python
1. Take an integer as input: this is the total count of items to store in the list.
2. Loop for count times to get user inputs and append the input items to a list user_list.
3. Create a function print_list_index (), with my_list as a parameter.
o Inside the function, loop over the my_list and print "<element_in_list> is at index <index>"
4. Call the function print_list_index () with user_list as an argument in your main program.
Input
5
apple
banana
cherry
mango
pear
Output
apple is at index 0
banana is at index 1
cherry is at index 2
mango is at index 3
pear is at index 4
Hints / Two alternative approaches
●
If you are getting user input inside of the loop, remember that you can reuse the variable after you append its contents to the list.
fruits = []
counter = 0
for count in range (counter):
fruit = input ()
fruits.append (fruit)
Transcribed Image Text:1. Take an integer as input: this is the total count of items to store in the list. 2. Loop for count times to get user inputs and append the input items to a list user_list. 3. Create a function print_list_index (), with my_list as a parameter. o Inside the function, loop over the my_list and print "<element_in_list> is at index <index>" 4. Call the function print_list_index () with user_list as an argument in your main program. Input 5 apple banana cherry mango pear Output apple is at index 0 banana is at index 1 cherry is at index 2 mango is at index 3 pear is at index 4 Hints / Two alternative approaches ● If you are getting user input inside of the loop, remember that you can reuse the variable after you append its contents to the list. fruits = [] counter = 0 for count in range (counter): fruit = input () fruits.append (fruit)
fruit = input (
fruits.append (fruit)
• Use the enumerate() function to get indices and elements simultaneously. Try running the following code to see how it works:
fruits = ["apple", "banana", "cherry", "mango", "pear"]
for index, fruit in enumerate (fruits):
print (f"Index {index), fruit = {fruit)")
• Alternatively, use the for index in range (len (...)) construct to manually index the list to retrieve the value of the element at
that index. Try running the following code to see how it works:
fruits = ["apple", "banana", "cherry", "mango", "pear"]
for index in range (len (fruits)) :
print (f"Index (index), fruit = {fruits [index]}")
422020.2684366.qx3zqy7
LAB
ACTIVITY
1 def print_list_index( my_list ):
2
3
4
4.16.1: CHECKPOINT LAB: Print List Indices and Items
11
12
13
14
15
||||||
Given an input list my_list,
display "<item> is at index <N>"
for each item in the list.
###
5
6
7
8
9 if __name__ == "__main__":
10
main.py
pass # TODO: replace with the proper output
user_list = []
count= int(input())
#TODO: Create a for loop to get <count> user inputs and insert them into user_list
#TODO: Call print_list_index
0/17
Load default template...
Transcribed Image Text:fruit = input ( fruits.append (fruit) • Use the enumerate() function to get indices and elements simultaneously. Try running the following code to see how it works: fruits = ["apple", "banana", "cherry", "mango", "pear"] for index, fruit in enumerate (fruits): print (f"Index {index), fruit = {fruit)") • Alternatively, use the for index in range (len (...)) construct to manually index the list to retrieve the value of the element at that index. Try running the following code to see how it works: fruits = ["apple", "banana", "cherry", "mango", "pear"] for index in range (len (fruits)) : print (f"Index (index), fruit = {fruits [index]}") 422020.2684366.qx3zqy7 LAB ACTIVITY 1 def print_list_index( my_list ): 2 3 4 4.16.1: CHECKPOINT LAB: Print List Indices and Items 11 12 13 14 15 |||||| Given an input list my_list, display "<item> is at index <N>" for each item in the list. ### 5 6 7 8 9 if __name__ == "__main__": 10 main.py pass # TODO: replace with the proper output user_list = [] count= int(input()) #TODO: Create a for loop to get <count> user inputs and insert them into user_list #TODO: Call print_list_index 0/17 Load default template...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education