Try using this:

for k in range(1,c+1,2):
Answer from carlosdc on Stack Overflow
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_for_loops.asp
Python For Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
🌐
Python
peps.python.org β€Ί pep-0284
PEP 284 – Integer for-loops | peps.python.org
March 1, 2002 - One of the most common uses of for-loops in Python is to iterate over an interval of integers. Python provides functions range() and xrange() to generate lists and iterators for such intervals, which work best for the most frequent case: half-open intervals increasing from zero.
🌐
Real Python
realpython.com β€Ί python-for-loop
Python for Loops: The Pythonic Way – Real Python
February 23, 2026 - In this code, the loop in the highlighted line iterates over integer indices from 0 to 5 in an asynchronous manner. When you run this script, you get the following output: ... In this output, each number is obtained after waiting half a second, ...
🌐
w3resource
w3resource.com β€Ί python β€Ί python-for-loop.php
Python for loop
September 20, 2024 - ... In this example, we count the number of even and odd numbers from a tuple. numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple count_odd = 0 count_even = 0 for x in numbers: if x % 2: count_odd+=1 else: count_even+=1 print("Number ...
🌐
Reddit
reddit.com β€Ί r/learnprogramming β€Ί how to create a for loop using an integer input??
r/learnprogramming on Reddit: How to create a for loop using an integer input??
February 4, 2025 -

Hello! I'm new to coding and I'm learning for loops, and decided to start playing around with them, because why not? I for the LIFE of me can't figure out how to get a for loop to print the word "Python" for the amount of the number I input lol. What I'm essentially trying to do is have an input ask me "How many times can you say python", and whatever my integer input is, iterate "Python" that number of times. This is what I IMAGINE it would look like, but to no avail. (Sorry if this code looks silly, it doesn't even work but I'm trying LOL!)

python_count = int(input("How many times can you say python?"))                   say_python = python_count                                                               for x in say_python:                                                       print("Python!")
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί is there a clean way to treat "i" in a for loop as an integer? (example code inside)
r/learnpython on Reddit: Is there a clean way to treat "i" in a for loop as an integer? (Example code inside)
February 26, 2019 -

I wrote an example code. I want to treat "i" in the for loop as an integer. In this case I needed it to index though a list. I find myself writing a "counting variable" really often, and I was wondering if there was a better way to write it.

#this program will form pairs of fighters from the fighters list 

fighters = ['ryu', 'ken', 'zangief', 'balrog', 'chun-li', 'blanka', 'sagat', 'ehonda']

count = 0

for i in range(int(len(fighters)/2)):
     print(fighters[count] + " will fight " + fighters[count + 1])
     count = count + 2
Top answer
1 of 5
106
Rather than have a counting variable, you could enumerate: for index, value in enumerate(fighters): print(index, value) 0 ryu 1 ken 2 zangief 3 balrog 4 chun-li 5 blanka 6 sagat 7 ehonda For your given example, though, you could zip: for first, second in zip(fighters, fighters[2:]): print(first, second) ryu zangief ken balrog zangief chun-li balrog blanka chun-li sagat blanka ehonda You could also check out combinations , although it'll produce more pairings than your current version, it's a bit easier to use. Edit: Editor mangling. Edit: u/CylonSaydrah has suggested the following improvement to the zip version, which uses a step of 2 to skip elements in each list: for first, second in zip(fighters[::2],fighters[1::2]):
2 of 5
11
Short answer: i is already an integer. Long Answer The range() built-in allows you iterate over a range of numbers, so in the sequence for i in range(10), i starts at 0 and counts up to 9 for the duration of the loop. >>> for i in range(10) ... print(f"{type(i)} {i}") ... 0 1 2 # -- 8< SNIP --- Another note is that it's not necessary to call int() on len(fighters) / 2 if you want to truncate the result; instead, use the floor division operator // (IIRC it always rounds down). Anyway, for the code snippet you provided, you don't need to use // anyway as you can just leverage range()'s step parameter. range() doesn't take keyword arguments, so you have to specify the start index (0) as well: for i in range(0, len(fighters), 2): print(fighters[i] + " will fight " + fighters[i+1]) However, if the roster is always going to be ordered the same, you can also couple the fighters in tuples: fighters = [("ruy", "ken"), ("zangief", "balrog"), ("chun-li", "blanka"), ("sagat", "ehonda")]. You may also want to take a look at zip() which does the above: >>> player1 = ["ruy", "zangief", "chun-li", "sagat"] >>> player2 = ["ken", "balrog", "blanka", "ehonda"] >>> zipped = zip(player1, player2) >>> list(zipped) [('ruy', 'ken'), ('zangief', 'balrog'), ('chun-li', 'blanka'), ('sagat', 'ehonda')] Then you just iterate over zipped: >>> for pair in zipped: ... print(pair[0] + " will fight " + pair[1]) EDIT: Thanks to u/warbird2k for pointing out that you can iterate over zipped immediately without wrapping it in a list.
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί python_for_loops.htm
Python - For Loops
Python's list object is also an indexed sequence, and hence you can iterate over its items using a for loop. In the following example, the for loop traverses a list containing integers and prints only those which are divisible by 2.
Find elsewhere
🌐
OpenStax
openstax.org β€Ί books β€Ί introduction-python-programming β€Ί pages β€Ί 5-2-for-loop
5.2 For loop - Introduction to Python Programming | OpenStax
March 13, 2024 - The program must print the number of spaces counted. Ex: If the input is "Hi everyone", the program outputs 1. ... Write a program that reads two integer values, n1 and n2, with n1 < n2, and performs the following tasks:
🌐
Codementor
codementor.io β€Ί community β€Ί making python integers iterable
Making Python Integers Iterable | Codementor
December 10, 2020 - In the example below, we see how a list a is iterated through using a for ... in loop and each element can be accessed via variable x. >>> a = [2, 3, 5, 7, 11, 13] >>> for x in a: print(x, end=" ") 2 3 5 7 11 13 Β· Similar to list, range is ...
🌐
Python
wiki.python.org β€Ί moin β€Ί ForLoop
ForLoop - Python Wiki
While loop from 1 to infinity, therefore running forever. x = 1 while True: print("To infinity and beyond! We're getting close, on %d now!" % (x)) x += 1 Β· When running the above example, you can stop the program by pressing ctrl+c at the same time. As you can see, these loop constructs serve different purposes.
🌐
TutorialsPoint
tutorialspoint.com β€Ί how-to-use-for-loop-in-python
How to use for loop in Python?
March 10, 2021 - Python's list object is also an indexed sequence, and hence you can iterate over its items using a for loop. In the following example, the for loop traverses a list containing integers and prints only those which are divisible by 2.
🌐
W3Schools
w3schools.com β€Ί python β€Ί gloss_python_for_range.asp
Python Looping Through a Range
Python For Loops Tutorial For Loop Through a String For Break For Continue For Else Nested Loops For pass
🌐
Snakify
snakify.org β€Ί for loop with range
For loop with range - Learn Python 3 - Snakify
for loop iterates over any sequence. For instance, any string in Python is a sequence of its characters, so we can iterate over them using for: ... Another use case for a for-loop is to iterate some integer variable in increasing or decreasing order.
🌐
Statistics Globe
statisticsglobe.com β€Ί home β€Ί python programming language for statistics & data science β€Ί loop through list of integers in python (3 examples)
How to Loop Through List of Integers in Python (3 Examples)
June 20, 2023 - In this example, we have a list of integers called numbers. The for loop iterates over each element in the list, and we print each value of num.
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu β€Ί notebooks β€Ί chapter05.01-For-Loops.html
For-Loops β€” Python Numerical Methods
EXAMPLE: Given a list of integers, a, add all the elements of a. s = 0 a = [2, 3, 1, 3, 3] for i in a: s += i # note this is equivalent to s = s + i print(s) ... The Python function sum has already been written to handle the previous example. However, assume you wish to add only the even numbers.
🌐
Dataquest
dataquest.io β€Ί blog β€Ί python-for-loop-tutorial
Python for Loop: A Beginner's Tutorial – Dataquest
March 10, 2025 - Finally, we'll convert the range numbers to integers using Python's built-in int() function, and replace the original strings with these integers in our data set. for row in ev_data[1:]: # loop through each row in ev_data starting with row 2 ...