Try using this:

for k in range(1,c+1,2):
Answer from carlosdc on Stack Overflow
๐ŸŒ
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.
Discussions

How to create a for loop using an integer input??
Replace the 0 in count = 0 with your integer. count = 0 for i in range(0,count): print("Python") More on reddit.com
๐ŸŒ r/learnprogramming
23
12
February 4, 2025
python - I want to get an integer input from a user and then make the for loop iterate through that number, and then call a function that many times - Stack Overflow
so I've been struggling with this for a while now. I want my program to ask a user "How many times to print Hello world?" and then get the number from that and use it in a for loop to cal... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a clean way to treat "i" in a for loop as an integer? (Example code inside)
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]): More on reddit.com
๐ŸŒ r/learnpython
53
116
February 26, 2019
For Loop in Python
Pardon if I have been posting series of questions. Newbie Python learner here, and am going through PCEP materials, and having some questions along the wayโ€ฆ Thank you in advance for the help. In these two codes, I confused why the answer is such: Code 1: my_list = [0,1,2,3] x = 1 for elem ... More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
September 7, 2023
๐ŸŒ
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).
๐ŸŒ
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!")
๐ŸŒ
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, ...
๐ŸŒ
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:
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Snakify
snakify.org โ€บ for loop with range
For loop with range - Learn Python 3 - Snakify
To iterate over a decreasing sequence, we can use an extended form of range() with three arguments - range(start_value, end_value, step). When omitted, the step is implicitly equal to 1. However, can be any non-zero value. The loop always includes start_value and excludes end_value during iteration:
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-for-loop.php
Python for loop
September 20, 2024 - ... In this example, we count the ... 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 of even numbers :",count_even) print("Number of odd numbers :",count_odd) ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
For Loop in Python - Python Help - Discussions on Python.org
September 7, 2023 - In these two codes, I confused why the answer is such: Code 1: my_list = [0,1,2,3] x = 1 for elem in my_list: x *= elem print (x) Answer: [0] Code 2: my_list = [0,1,2,3] x = 1 for elem in my_list: new_list = x * elem print (new_list) Answer: ...
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-for-loops
Python For Loops - GeeksforGeeks
The else block just after for/while is executed only when the loop is NOT terminated by a break statement. ... In Python, enumerate() function is used with the for loop to iterate over an iterable while also keeping track of index of each item.
Published ย  4 weeks ago
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ loops-in-python
Loops in Python - GeeksforGeeks
The continue statement in Python returns the control to the beginning of the loop. ... for letter in 'geeksforgeeks': if letter == 'e' or letter == 's': continue print('Current Letter :', letter) ... Current Letter : g Current Letter : k Current Letter : f Current Letter : o Current Letter : r Current Letter : g Current Letter : k ยท Explanation: The continue statement is used to skip the current iteration of a loop and move to the next iteration.
Published ย  1 week ago