0% found this document useful (0 votes)
5 views9 pages

Python Loop Programs and Examples

The document outlines a series of Python programming exercises focused on loops, including tasks such as printing greetings, calculating sums, finding factorials, and generating Fibonacci series. It also includes specific instructions for using 'for' loops, as well as explanations of 'break' and 'continue' statements in loops. Each exercise is followed by a placeholder for output, indicating the expected results of the programs.

Uploaded by

Hardik Khakurel
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)
5 views9 pages

Python Loop Programs and Examples

The document outlines a series of Python programming exercises focused on loops, including tasks such as printing greetings, calculating sums, finding factorials, and generating Fibonacci series. It also includes specific instructions for using 'for' loops, as well as explanations of 'break' and 'continue' statements in loops. Each exercise is followed by a placeholder for output, indicating the expected results of the programs.

Uploaded by

Hardik Khakurel
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

Programs on Loops

1. Write a python program to print “Hello” 5 times.

O/p:

2. Write a python program to accept a greeting from the user and print it on the screen. This
operation should continue till the user enters “done”

O/p:

3. Write a python program to calculate the sum of the numbers the user enters. The
calculation to stop if user enters 0.
O/p:

4. Write a python program to print the square of all numbers from 1 to 10.

O/p:

5. Write a python program to find the sum of all even numbers from 0 to n.
O/p:

6. Write a python program to find the number of digits in a given number.

O/p:

7. Write a program to calculate find factorial of a number.


O/p:

8. Write a python program to find GCD of two numbers.

O/p:

For loop
1. Write a program to print numbers from 0 to 5 using range and for.

O/p:

2. Write a program to print numbers from 2 to 5 using range and for.


O/p:

3. Write a program to print numbers from 2 to 30 in skips of 3.

O/p:

4. Write a program to print fibonacci series of n numbers.

O/p:
5. Write a program to check if a number is prime or not.

O/p:

6. Write a program to print multiplication table of a given number

O/p:
7. Write a program to print prime numbers in a given range.

O/p:

8. Printing patterns using nested loop.


a.
b.

O/p:

break and continue

break : Comes out of the loop completely.

continue : Skips only the current iteration

break:
O/p:

continue:

O/p:

You might also like