Today you will practice using for loops in Python. Loops help us repeat tasks efficiently. Try these problems step by step.
Remember to use a for loop in each program instead of repeating code manually!
Assignment 01: Number Printing
Use a for loop to print numbers in a sequence.
Objective:
Understand how to use a for loop with the range() function.
Instructions:
- Print numbers from 1 to 20.
- Print only the even numbers between 1 and 50.
- Print the multiplication table of 7 using a for loop.
Assignment 02: Pattern Printing
Use nested for loops to display simple patterns.
Objective:
Learn how to use loops inside loops (nested loops) to create shapes or patterns.
Instructions:
- Print a triangle pattern like this:
*
**
***
****
*****
- Print a reverse triangle pattern:
*****
****
***
**
*
Assignment 03: Sum of Numbers
Use a for loop to calculate the sum of numbers.
Objective:
Practice adding numbers inside a loop to get a total.
Instructions:
- Ask the user to enter a number
n.
- Use a for loop to calculate the sum of numbers from 1 to
n.
- Display the final result as "The sum of numbers from 1 to n is: X".
If you need help
Post in the group with any of these problems:
- Not sure how
range() works
- Confused about nested loops
- Unable to calculate sum inside a loop
Good luck and keep practicing!