🌐
PYnative
pynative.com › home › python exercises › python loops exercises: 40+ coding problems with solutions
40 Python Loops Coding Exercises with Solutions – PYnative
June 13, 2026 - This article provides 40+ Python loop practice questions that focus entirely on loops (for, while, and nested loops) and control flow statements. Each coding challenge includes a Practice Problem, Hint, Solution code, and detailed Explanation, ensuring you don’t just copy code, but genuinely practice and understand how and why it works. All solutions have been fully tested on Python 3. Use our Online Code Editor to solve these exercises in real time.
🌐
GitHub
github.com › Asabeneh › 30-Days-Of-Python › blob › master › 10_Day_Loops › 10_loops.md
30-Days-Of-Python/10_Day_Loops/10_loops.md at master · Asabeneh/30-Days-Of-Python
Iterate 10 to 0 using for loop, do the same using while loop. Write a loop that makes seven calls to print(), so we get on the output the following triangle: ... # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ... 0 x 0 = 0 1 x 1 = 1 2 x 2 = 4 3 x 3 = 9 4 x 4 = 16 5 x 5 = 25 6 x 6 = 36 7 x 7 = 49 8 x 8 = 64 9 x 9 = 81 10 x 10 = 100 · Iterate through the list, ['Python', 'Numpy','Pandas','Django', 'Flask'] using a for loop and print out the items.
Author   Asabeneh
Discussions

Ideas for practicing for and while loops?

For: print out only even numbers between 1 and 100. Now do it without using an if statement.

While: Ask the user for a secret password. Keep going until they get it right. Now do the same without using an if statement.

These are probably the most basic ideas. Once you have them down, you can build on your knowledge.

More on reddit.com
🌐 r/learnpython
34
56
October 2, 2020
For loops and while loops
I get what you are saying :) I need a lot of practice for stuff to stick. When I was learning conditionals and looping, the best advice I got was to start with some practice problems, then make up similar problems with my own data and scenarios. For example, you could write a program to loop through a list of addresses and have it return some information about each entry. Or, you could write a program to take keyboard input and keep printing some result until you enter 'N' (the while loop in action). We were also told to try to solve the problems without using while or for loops to help motivate why you would want them in the first place. That really helped solidify the concepts for me, because you can write code without the loops, but it gets long and tedious... Btw, another link I used was https://www.practicepython.org/ . More on reddit.com
🌐 r/learnpython
6
3
June 9, 2018
Python exercises to practice skills

Nice thank you

More on reddit.com
🌐 r/learnpython
12
147
September 27, 2018
Resource: Python Exercises, Practice Problems and Solutions for Beginners
If you're aiming to improve your problem solving skill try the following sites: codesignal.com | www.coderbyte.com | www.codewars.com With that being said, above all, it’s important that you learn to think like a programmer! The bellow paragraphs is a VERY important concept extracted from Jean Paul Knight book titled: “LEARN PYTHON WITH NO PROGRAMMING EXPERIENCE” [ a book that I will strongly suggest you to buy an read ] There is a way that programmers think that is different from the rest of the world. If you want to understand functions and other programming concepts, you must have the right mindset. Why is it important to think like a programmer? Before we go deeper into functions and other Python concepts, we must look at a crucial mindset. The mindset of a programmer. When you have this mindset, you will find it much easier to bridge the gap between beginner and intermediate. You will also be able to quickly remove any mental block that cause you to struggle. On the other hand, without the right mindset you may find yourself stuck way too often. You may find it hard to progress beyond tutorials. In particular, it may be hard to start making your own programs. Worse still, documentation ( often badly written ) will be enough to stop you in your tracks. There is another reason why having the right mindset is important. If you are using Python to automate stuff, you’ll be more likely to find quick solutions. If Python is required for you job, you will write code that impresses your peers, and more importantly your boss. Even if you code for yourself, the right kind of thinking will make your work easier, faster, and more efficient. Don’t skip the mindset bit! I believe the biggest reason why people get stuck in “newbie” mode is not understanding how programming works. Let’s take a deeper look. What does thinking like a programmer mean? For the purpose of this guide, we will use a very simple defition. A programmers mindset is a way of thinking that focuses on creating useful and practical solutions to problems. It means you grasp the basic fundamentals that make you a good programmer. The challenge is, that the programmers mindset doesn’t have much to do with coding. That’s what trips up many beginners. For instance, many people spend a lot of time on syntax. It’s kind of like putting on a stage show. The hard work happens during the reahersals, behind the scenes. Then, When it comes to programming, most of your work happens before you start up your favorite code editor. The biggest mistake beginners make is… …focusing too much on the code. Yet, there are two skills that will make you a master - neither of them involve writing code. They are: Knowing how to learn Knowing how to solve problems. Great programmers always keep learning. There is no programmer who knows it all. So, as you progress you will always find yourself learning new libraries. You will also discover new concepts along the way. The key to becoming better is accepting that you’ll always be a learner. For this reason, you need to have skills that allow you to learn quickly. The other keys is knowing how to solve problems. When it comes to problem solving, the computer is not your best friend. In fact, the computer is your servant but we’ll come back to that later. Your true best friend is a piece of paper ( and a pen! ) As a good programmer, you’ll need to be able to solve problems using pen and paper. Then, once you’ve solved the problem, you use the solution as your guide when writing the code. “OK, so what happens next?” Next we’re going to mix up learning Python with learning the right mindset. That way, you’ll naturally absorb the concepts you need to grasp. As a result, you’ll become better at using functions. At the same time, your overall programming skills will go to the next level. Let’s go! It’s time to discover why you need functions in the first place… Support the Author by getting his book HERE More on reddit.com
🌐 r/learnpython
20
234
July 17, 2018
🌐
LearnPython.com
learnpython.com › blog › python-loop-exercises
10 Python Loop Exercises with Solutions | LearnPython.com
January 29, 2024 - A great way for beginners to learn Python is by doing hands-on exercises. In this article, you’ll get 10 Python exercises for writing loops. You’ll also get the solutions with detailed explanations.
🌐
Scaleway
scaleway.com › en › docs › tutorials › python-for-loops
Getting started with Python for loops | Scaleway Documentation
July 28, 2025 - As we saw in an earlier example we can use loops with Python's built-in range() function to state exactly how many times we want the loop to iterate. ... With just one parameter, the range starts at a default of 0 and finishes at (not including) the specified number: ... With three parameters, we set the start and finish numbers of the range, and the step value (the interval between each iteration): for x in range(2, 10, 2): print(x) ## Output: 2 4 6 8
🌐
Pythonista Planet
pythonistaplanet.com › python-for-loop-examples
21 Python for Loop Exercises and Examples – Pythonista Planet
May 26, 2022 - # printing multiples of 5 till 20 for i in range(5,20,5): print(i) ... I hope this article was helpful. Check out my post on 18 Python while Loop Examples.
🌐
Python Basics
pythonbasics.org › home › python basics › python "for" loops (iteration introduction)
Python "for" Loops (Iteration Introduction) - pythonbasics.org
2. Create a loop that counts from 0 to 100 3. Make a multiplication table using a loop 4. Output the numbers 1 to 10 backwards using a loop 5. Create a loop that counts all even numbers to 10 6. Create a loop that sums the numbers from 100 to 200 ... Complete the function that returns the sum ...
🌐
w3resource
w3resource.com › python-exercises › python-conditional-statements-and-loop-exercises.php
Python conditional statements and loops - Exercises, Practice, Solution - w3resource
For numbers that are multiples of three and five, print "FizzBuzz". ... Write a Python program that takes two digits m (row) and n (column) as input and generates a two-dimensional array.
Find elsewhere
🌐
Python Lobby
pythonlobby.com › home › python loop exercises with solution – for loop(), while loop() etc.
Python Loop Exercises with Solution – for loop(), while loop() etc.
October 9, 2022 - # Program to separate +ve and -ve x = [23,4,-6,23,-9,21,3,-45,-8] pos = [] neg = [] for i in range(len(x)): if x[i] < 0: neg.append(x[i]) else: pos.append(x[i]) print("Positive numbers are: ",pos) print("Negative numbers are: ",neg) # output # Positive numbers are: [23, 4, 23, 21, 3] # Negative numbers are: [-6, -9, -45, -8] ... # Append a list with types of elements n = [23, 'Python',23.98] x = [] for i in range(len(n)): x.append(type(n[i])) print(n) print(x) # output # [23, 'Python', 23.98] #[<class 'int'>,<class 'str'>,<class 'float'>]
🌐
HolyPython
holypython.com › home › intermediate python exercises › exercise 8: for loop
Improve your Python skills with Exercise 8: For Loop | HolyPython.com
April 4, 2024 - Write a for loop that iterates through a string and prints every letter. ... When you iterate through a string it will go through the letters as strings have indexing too. ... Check out Holy Python AI+ for amazing Python learning tools.
🌐
W3Schools
w3schools.com › python › python_for_loops.asp
Python For Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp 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).
🌐
Mkzia
mkzia.github.io › eas503-book › chapters › 06 › for_loop_exercises.html
6.2. For Loop Exercises — EAS503: Python for Data Scientists
def coin_toss(number): import random random.seed(503) output = '' for i in range(number): toss = random.randint(0, 1) if toss == 0: output += 'H' else: output += 'T' return output def coin_toss_probability(number): result = coin_toss(number) head_count = 0 tail_count = 0 for ele in result: if ele == 'H': head_count += 1 elif ele == 'T': tail_count += 1 return (head_count / len(result), tail_count / len(result)) print(coin_toss_probability(100))
🌐
Python Course
python-course.eu › python-tutorial › for-loops.php
20. For Loops | Python Tutorial | python-course.eu
Write a program to find and print all prime numbers between 1 and 50 using a for loop. Print numbers from 1 to 42, but for multiples of 3, print "Fizz," and for multiples of 5, print "Buzz." For numbers that are multiples of both 3 and 5, print "FizzBuzz." This exercise is about the Ramanujan-Hardy ...
🌐
Llego
llego.dev › home › blog › practical exercises for learning loops in python
Practical Exercises for Learning Loops in Python - llego.dev
May 28, 2023 - These examples demonstrate how for loops work consistently across different sequence data types in Python. Generate a sequence of numbers using Python’s range() function: ... Prints numbers 0 through 4. ... Prints numbers 3 to 7. Omitting the step size defaults to increments of 1. ... Prints odd numbers from 1 to 9. ... These exercises demonstrate how to construct ranges for iteration in for loops.
🌐
TechBeamers
techbeamers.com › python-exercises-on-loops-conditions-range
Python Control Flow Exercises - TechBeamers
April 18, 2025 - Here are 45 Python exercises on loops (for, while), if-else statements, and the range() function, along with their solutions. Each exercise comes with a brief description of the problem and a solution…
🌐
Pythontutorials
pythontutorials.eu › basic › loops
Loops: for and while // Python Tutorials
You can also loop through a str, in which case you get individual characters as if you were looping through a list of characters. Use a for loop through loop through a str with the first five letters of the alphabet. Print out each character on a separate line.
🌐
Exercism
exercism.org › tracks › python › concepts › loops
Loops in Python on Exercism
Master Loops in Python by solving 93 exercises, with support from our world-class team.
🌐
Medium
ashaicy99.medium.com › python-nested-for-loops-practice-exercises-dee4e76a00bb
Python Nested for Loops Practice Exercises | by Asha Ganesh | Medium
June 9, 2020 - Nested for loops can be useful for iterating through items with in list composed of lists.In list composed of lists ,if we employ just one for loop ,the program will output each internal list as and item ... print single star at first row 2 stars in the second row and continue doing this in a similar fashion ... Will meet with many exercises with ‘break’ and ‘continue’ with loops in python.