Q:

Write a program in Python to keep count of this given list starting from 100

0

Write a program in Python to keep count of this given list starting from 100

The list of items is -

["Suger", "Tea", "Rice", "Wheat", "Salt", "Pulse"]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

The enumerate() is a predefined function in Python and used to add counter to an iteration and returns it in a form of enumerate object.

Syntax of Python enumerate()
enumerate(iterable, start=0)

Here, the iterable is a sequence, an iterator and start parameter is the number from where the counting starts. This is an optional parameter, by default 0 is taken as starting number.

This is the following solution to keep count of this given list starting from 100.

items = ["Suger", "Tea", "Rice", "Wheat", "Salt", "Pulse"]

# set the start index to 100
for count,ele in enumerate(items,100):
	print count,ele
Output of the above code

100 Suger

101 Tea

102 Rice

103 Wheat

104 Salt

105 Pulse

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Exercises, Practice Questions and Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program in Python to calculate the value o... >>
<< Write a list comprehension that returns all the pa...