0% found this document useful (0 votes)
9 views

Exercise Programs On While Loop

The document provides examples of while loop programs in Python including programs to add the first N natural numbers, find the product of the first N natural numbers, check if a number is a palindrome, find the factorial of a number, print squares of numbers from 0 to 10, find the sum of even numbers from 0 to 10, check how many numbers between a and b are divisible by c, and print a counting pattern from 1 to 99.

Uploaded by

sumanthcm.cse
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)
9 views

Exercise Programs On While Loop

The document provides examples of while loop programs in Python including programs to add the first N natural numbers, find the product of the first N natural numbers, check if a number is a palindrome, find the factorial of a number, print squares of numbers from 0 to 10, find the sum of even numbers from 0 to 10, check how many numbers between a and b are divisible by c, and print a counting pattern from 1 to 99.

Uploaded by

sumanthcm.cse
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/ 1

Exercise programs on while loop

1. Write a python program to add first N natural numbers


sum = 1+2+3+...+n
Hint: read value of n from user
Set initial value of sum to 0
Create loop which runs for n time
For each time while loop condition is true, add current value to sum

2. Write a python program to find product first N natural numbers


product = 1*2*3*...*n
Hint: read value of n from user
Set initial value of product to 1
Create loop which runs for n time
For each time while loop condition is true, multiply current value with product
and store result into product

3. Write a python program to reversing a number using while loop and check that number is
a palindrome or not.
4. Write a python program to find the factorial of a given number using while loop.
5. Write a python program to print the square of all numbers from 0 to 10
6. Write a python program to find the sum of all even numbers from 0 to 10
7. Write a python program to read three numbers (a,b,c) and check how many numbers
between ‘a’ and ‘b’ are divisible by ‘c’
8. Write a python program to get the following output
1-----99
2-----98
3-----97
..
..
..
98-----2
99-----1

You might also like