Use enumerate() like so:

def draw_menu(options, selected_index):
    for counter, option in enumerate(options):
        if counter == selected_index:
            print " [*] %s" % option
        else:
            print " [ ] %s" % option    

options = ['Option 0', 'Option 1', 'Option 2', 'Option 3']
draw_menu(options, 2)

Note: You can optionally put parenthesis around counter, option, like (counter, option), if you want, but they're extraneous and not normally included.

Answer from Evan Fosmark on Stack Overflow
🌐
Pierian Training
pieriantraining.com › home › counting in a python loop: a beginner’s guide
Counting in a Python Loop: A Beginner's Guide - Pierian Training
April 28, 2023 - The `for` loop then iterates over each number generated by `range()` and prints it out. Another example could be counting the number of characters in a string: my_string = "Hello World" count = 0 for char in my_string: count += 1 print("Number of characters:", count) In this example, we initialize a counter variable `count` to zero, then iterate over each character in the string using a `for` loop.
Discussions

Can you count the number of times a loop occurs?
Define a variable "counter" with value 0 before the loop. Before the end of each loop, increase the counter value by 1 ( counter = counter + 1). More on reddit.com
🌐 r/learnpython
6
4
February 7, 2021
python - Get loop count inside a for-loop - Stack Overflow
This for loop iterates over all elements in a list: for item in my_list: print item Is there a way to know within the loop how many times I've been looping so far? For instance, I want to take a More on stackoverflow.com
🌐 stackoverflow.com
Creating a counter inside a Python for loop - Stack Overflow
Obviously, if we do this, the counter will remain at 0 as it is reset at the start of every iteration: for thing in stuff: count = 0 print count count =+1 write_f.write(thing) But ... More on stackoverflow.com
🌐 stackoverflow.com
Can not understand for loops
You're following a recipe for potato soup. It says "wash and peel five potatoes." But you only know how to wash and peel one potato. So you wash and peel one potato, then another, then another, until you've done it to five potatoes. That's a for loop: "for each of five potatoes, wash the potato, then peel it." More on reddit.com
🌐 r/learnpython
90
262
August 14, 2021
People also ask

How does a for loop work in Python?
A for loop in Python is used to iterate over an iterable object, executing a block of code for each item in the iterable. The iterable could be a list, tuple, string, dictionary, set, or any other object that supports iteration.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › for-loop-counter-python
For Loop Counter in Python: Explained – Kanaries
What is the purpose of the enumerate() function in Python?
The enumerate() function in Python adds a counter to an iterable and returns it as an enumerate object. This built-in function makes it easier to iterate over an object along with an index representing the position of the current item.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › for-loop-counter-python
For Loop Counter in Python: Explained – Kanaries
How can I create a custom function similar to enumerate()?
A custom function mimicking enumerate() can be created using a generator function. This function would yield a tuple of the counter and the current item for each iteration over the iterable. Check out the 'Crafting a Custom Function Equivalent to Enumerate()' section of this article for a detailed example.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › for-loop-counter-python
For Loop Counter in Python: Explained – Kanaries
🌐
Real Python
realpython.com › python-enumerate
Python enumerate(): Simplify Loops That Need Counters – Real Python
June 23, 2025 - Python’s enumerate() lets you write Pythonic for loops when you need a count and the value from an iterable. The significant advantage of enumerate() is that it returns a tuple with the counter and value, so you don’t have to increment the counter yourself.
🌐
Kanaries
docs.kanaries.net › topics › Python › for-loop-counter-python
For Loop Counter in Python: Explained – Kanaries
June 8, 2023 - A for loop in Python is utilized to iterate over an iterable (like a list, tuple, dictionary, string, or range) executing a block of code for each item in the iterable. Typically, when we iterate over a sequence in a for loop, we don't have a built-in counter to keep track of the index.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-count-in-for-loop
How to count in a For or While Loop in Python | bobbyhadz
Use the `enumerate()` function to count in a for loop, e.g. `for index, item in enumerate(my_list):`.
🌐
Tutorial Reference
tutorialreference.com › home › python › examples › faq › how to count in for and while loops in python
How to Count in For and While Loops in Python | Tutorial Reference
March 29, 2025 - Learn how to count iterations in Python `for` and `while` loops using `enumerate()`, manual counters, `range()`, and best practices for tracking loop progress.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › can you count the number of times a loop occurs?
r/learnpython on Reddit: Can you count the number of times a loop occurs?
February 7, 2021 -

I'm new to python, sorry if my wording is terrible.

I'm building a very basic number guessing game. I don't want to copy and paste the whole code into here unless someone wants it in the comments.

I have it so that you guess a number between 1-100. After each guess it will tell you if it's too low or too high. Once you guess it correct it will say "Correct!". I want it to also tell you how many attempts it took you to find the correct answer and print that out with the "Correct!". How do you do that?

🌐
CodeRivers
coderivers.org › blog › for-loop-counter-python
Mastering the For Loop Counter in Python - CodeRivers
February 22, 2026 - A for loop in Python iterates over ... However, a loop counter can be introduced to add more functionality. A counter is a variable that keeps track of the number of times the loop has executed....
🌐
Java2Blog
java2blog.com › home › python › how to count in python loop
How to Count in Python Loop [ 3 Ways ] - Java2Blog
October 17, 2023 - Counting in a loop means making a note of every iteration to find the total number of iterations after the loop has stopped running. If you want to count in while loop, skip to count in while loop section. The enumerate() function takes an iterable and assigns a counter variable to each element.
🌐
Medium
medium.com › @sami.hamdiapps › mastering-loop-counters-in-python-a-beginners-guide-dcb812c73c3c
Mastering Loop Counters in Python: A Beginner’s Guide | by Sami Hamdi | Medium
June 19, 2025 - For instance, when used with dictionaries, loop counters can help iterate through key-value pairs. Similarly, sets and tuples can access each element in these data structures. The flexibility of loop counters handling different data structures makes them a powerful tool in Python programming.
🌐
CodeRivers
coderivers.org › blog › python-for-loop-counter
Python For Loop Counter: A Comprehensive Guide — CodeRivers
In Python programming, loops are essential constructs that allow you to execute a block of code multiple times. Among the different types of loops, the `for` loop is widely used. A `for` loop counter can be a crucial element when you need to keep track of the number of iterations or perform operations based on the iteration number.
🌐
Kodeclik
kodeclik.com › loop-count-in-python
Get a loop count inside a Python for loop
October 16, 2024 - When you are in a for loop and you need a count of the loop index, the Python-ic way to obtain it is to use enumerate(), a function that returns both the index and the object.
🌐
Talkerscode
talkerscode.com › howto › python-for-loop-counter-variable.php
Python For Loop Counter Variable - TalkersCode.com
In simple terms, a counter variable is a variable that keeps trace of the number of times a special piece of code is implemented. In Python, a for loop is generally written as a loop over an iterable object.
🌐
Kodeclik
kodeclik.com › how-to-count-in-a-loop-python
Simplify Python loop counting with enumerate()
December 26, 2024 - Get loop count inside a for loop in Python using the enumerate() function. enumerate() takes an iterable as input and returns two values: 1. the index and 2. the value from the iterable.
🌐
AskPython
askpython.com › python › examples › countdown-with-for-loops
Countdown with For Loops in Python: With Tips and Examples - AskPython
March 22, 2023 - We can use the for loop to repeatedly iterate over the sequence after reversing it to count down.
🌐
BBC
bbc.co.uk › bitesize › guides › z3khpv4 › revision › 4
Count-controlled loops - using FOR - Iteration in programming - KS3 Computer Science Revision - BBC Bitesize
February 15, 2023 - The ‘for’ statement is used to specify where the loop starts. The ‘range’ statement specifies how many times the loop is to happen. The variable ‘count’ controls the iteration. With each iteration, Python automatically adds 1 to the value of ‘count’.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python for Loop (With range, enumerate, zip) | note.nkmk.me
August 18, 2023 - In Python, the for loop doesn't require a counter variable, and you can use any name for the loop variable:
🌐
Stack Abuse
stackabuse.com › guide-to-enumerate-in-python-forget-loops-with-counters
Guide to enumerate() in Python - Easy for Loops with Counting
January 31, 2022 - You can, without any extra dependencies, loop through an iterable in Python, with an automatic counter variable/index with syntax as simple as: for idx, element in enumerate(some_list): print(idx, element)