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: