- Basics of for loops in Python
- Different types of for loop in Python
- Beginner-friendly for loop examples in Python for practice
- Simple for loop programs in Python with answers
- Common errors and how to fix them
Q1. Print numbers from 1 to 10
for i in range(1, 11): print(i)
Explanation: range(1, 11)
generates numbers 1–10. The loop prints each number one by one.
Q2. Print squares of numbers from 1 to 5
for i in range(1, 6): print(i**2)
Explanation: Each number is squared using i**2
.
Q3. Print all vowels in a string
word = "programming" for ch in word: if ch in "aeiou": print(ch)
Explanation: Iterates through each character and prints vowels only.
Q4. Find the sum of even numbers from 1 to 20
total = 0 for i in range(2, 21, 2): total += i print(total)
Explanation: The loop adds all even numbers between 1–20.
Q5. Print multiplication table of 7
for i in range(1, 11): print(f"7 x {i} = {7*i}")
Explanation: Prints 7’s multiplication table using formatted string.
Q6. Reverse a string using a for loop
text = "Python" rev = "" for ch in text: rev = ch + rev print(rev)
Explanation: The string is reversed when each character is inserted in front.
Q7. Count how many times “a” appears in a string
word = "banana" count = 0 for ch in word: if ch == "a": count += 1 print(count)
Explanation: The loop calculate how many times "a"
appears in the string.
Q8. Print all elements in a list
numbers = [10, 20, 30, 40] for num in numbers: print(num)
Explanation: Loops directly over the list and prints each element.
Q9. Find factorial of a number
n = 5 fact = 1 for i in range(1, n+1): fact *= i print(fact)
Explanation: Multiplies numbers from 1 to 5 to calculate factorial.
Q10. Nested loop – Print a star pattern
for i in range(1, 6): for j in range(i): print("*", end="") print()
Explanation: Outer loop controls rows, inner loop prints stars in increasing order.