Learn with Yasir

Share Your Feedback

Python for Loop Exercises – Practice Iteration with Coding Tasks

Sharpen your Python skills with beginner-friendly for loop exercises. Practice iteration, range, nested loops, and real coding tasks to master Python loops step-by-step.

Topic: loops-for


🧪 Coding Exercises

🟢 Beginner Exercises

  1. Print 'Python' 5 times
  2. Write a `for` loop to print the word "Python" five times.
    

    Requirements

    • Use a for loop
    • Print exactly 5 times

    Expected Output

    Python
    Python
    Python
    Python
    Python
    

    📚 📺 Watch the solution now!


  3. Print numbers 0 to 9
  4. Write a `for` loop to print numbers from 0 to 9.
    

    Requirements

    • Use a for loop
    • Print numbers 0 through 9 inclusive

    Expected Output

    0 1 2 3 4 5 6 7 8 9

    📚 📺 Watch the solution now!


  5. Print even numbers 2 to 20
  6. Write a `for` loop to print all even numbers from 2 to 20.
    

    Requirements

    • Use a for loop
    • Print only even numbers
    • Include 2 and 20 if applicable

    Expected Output

    2 4 6 8 10 12 14 16 18 20

    📚


  7. Print each character in a string
  8. Write a `for` loop to iterate through the string "Hello, World!" and print each character.
    

    Requirements

    • Iterate through each character
    • Print each character on a new line

    Expected Output

    H
    e
    l
    l
    o
    ,
     
    W
    o
    r
    l
    d
    !
    

    📚 📺 Watch the solution now!


  9. Find the factorial of a number
  10. Write a `for` loop to calculate the factorial of a given number, e.g., 5! = 5 × 4 × 3 × 2 × 1.
    

    Requirements

    • Use a for loop
    • Calculate factorial correctly
    • Handle input 0 (0! = 1)

    Input

    5

    Expected Output

    120

    📚 📺 Watch the solution now!


  11. Squares of numbers 1 to 5
  12. Write a Python for loop that prints the square of each number from 1 to 5.
    

    Requirements

    • Use a for loop
    • Print square of each number

    Expected Output

    1 4 9 16 25

    📚 📺 Watch the solution now!


  13. Count down from 10 to 1
  14. Use a `for` loop to print numbers from 10 down to 1.
    

    Requirements

    • Use a for loop
    • Print numbers in descending order

    Expected Output

    10 9 8 7 6 5 4 3 2 1

    📚 📺 Watch the solution now!


  15. Calculate the sum of the first N natural numbers
  16. Calculate the sum of the first N natural numbers using a for loop.
    

    Requirements

    • Use a for loop
    • Calculate correct sum

    Input

    5

    Expected Output

    15

    📚 📺 Watch the solution now!


🟡 Intermediate Exercises

🔴 Advanced Exercises

🧠 Practice & Progress

Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules