# P-Assignment 4: While loop

Hi,

Please do the following programs using while loop.

**Part 1 :**

- Write a python script to print the numbers from 1 to 50.
- Write a python script to print the numbers from 50 to 1.
- Write a python script to print the even numbers from 1 to 50 using if condition.
- Write a python script to print the even numbers from 1 to 50 with out using if condition.
- Write a python script to print the factorial of a given number.
- Write a python script to print the prime numbers from 1 to 20.
- Write a python script to print the prime numbers between 100 to 130.
- Write a python script to print the Fibonacci series up to a given number.
- Write a python script to print the multiplication table of a given number in the following format.

Ex:- if the number is 5.

**Model a:**

5 * 1 = 5

5 * 2= 10

5 * 3 = 15

5 * 4 = 20

5 * 5= 25

5 * 6 = 30

5 * 7= 35

5 * 8 = 40

5 * 9 = 45

5 * 10= 50

**Model b:**

5 * 1 = 5

5 * 3 = 15

5 * 5= 25

5 * 7= 35

5 * 9 = 45

**Model c:**

5 * 2= 10

5 * 4 = 20

5 * 6 = 30

5 * 8 = 40

5 * 10= 50

10. Write a python script to print the ASCII characters using while loop. ( A-Z) and (a-z)

Note:-

To convert a number to ASCII use the following syntax

chr(number)

Ex: chr(65)

To convert a ASCII character to number use the following syntax

ord(character)

Ex: ord(‘A’)

**Part 2:**

- Write a python script to reverse a number using only while loop without any if condition.
- Write a python script to find the sum of digits in a number using while loop.

Ex:

Number =1234

Sum=10

- Write a python script to count the number of digits in a number.

Ex:

Number=1234

No. of digits=4

4 .Write a python script to check if a number is a palindrome or not using while and if combination.

- Write a python script to find the LCM of two numbers using if.
- Write a python script to find the sum of first ‘n’ natural numbers.
- Write a python script to find the product of first ‘n’ number of natural numbers.
- Write a python script to find the sum of even numbers between 20 to30.
- Write a python script to find the product of prime numbers between 5 to 20.
- Write a python script to check if a number is a strong number.

**Strong number: if sum of the factorial of its digit is equal to number itself.**

Ex:

** (1) 145 [Strong number]**

Digits are 1, 4, and 5

1! + 4! + 5! = 1+ 24 + 120 = 145.

** (2) 242 [Not a strong number]**

Digits are 2, 4 and 2

2! + 4! + 2! = 2 + 24 + 2 = 28 it is not equal to the given number 242.