0% found this document useful (0 votes)
7 views2 pages

Python Iteration Programs

The document provides Python programs demonstrating iteration statements using 'for' and 'while' loops. It includes examples for printing the first 10 natural numbers, printing numbers from 1 to 10, and printing even numbers between 1 and 20. Each program is accompanied by an algorithm outlining the steps involved.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Python Iteration Programs

The document provides Python programs demonstrating iteration statements using 'for' and 'while' loops. It includes examples for printing the first 10 natural numbers, printing numbers from 1 to 10, and printing even numbers between 1 and 20. Each program is accompanied by an algorithm outlining the steps involved.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Program - Iteration Statements

1. Program using 'for' loop

Aim:

To print the first 10 natural numbers using a for loop.

Algorithm:

1. Start the program.

2. Use a for loop to iterate from 1 to 10.

3. Print each number during iteration.

4. End.

Program:

for i in range(1, 11):

print(i)

2. Program using 'while' loop

Aim:

To print numbers from 1 to 10 using a while loop.

Algorithm:

1. Start the program.

2. Initialize a variable i = 1.

3. Use a while loop with the condition i <= 10.

4. Print the value of i and increment it.

5. End.
Program:

i=1

while i <= 10:

print(i)

i += 1

3. Program to print even numbers using loop

Aim:

To print all even numbers between 1 and 20 using a loop.

Algorithm:

1. Start the program.

2. Use a for loop to iterate from 1 to 20.

3. Check if the number is even using if (number % 2 == 0).

4. Print the number if it is even.

5. End.

Program:

for num in range(1, 21):

if num % 2 == 0:

print(num)

You might also like