Python LabExp1
Python LabExp1
: 1
DISPLAYING FIRST ‘N’ NATURAL NUMBERS
DATE:
AIM:
To write a Python program for displaying first ‘N’ natural numbers.
ALGORITHM:
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for displaying first ‘N’ natural numbers is written and output is
verified.
EX.NO.: 2
DISPLAYING FIRST ‘N’ ODD NUMBERS
DATE:
AIM:
To write a Python program for displaying first ‘N’ odd numbers.
ALGORITHM:
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for displaying first ‘N’ odd numbers is written and output is verified.
EX.NO.: 3
DISPLAYING FIRST ‘N’ EVEN NUMBERS
DATE:
AIM:
To write a Python program for displaying first ‘N’ even numbers.
ALGORITHM:
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for displaying first ‘N’ even numbers is written and output is verified.
EX.NO.:4
ODD OR EVEN NUMBER (ALTERNATIVE IF-ELSE)
DATE:
AIM:
To write a Python program to check whether the given number is odd or even.
ALGORITHM:
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program to check whether the given number is odd or even is written and
output is verified.
EX.NO.:6
COUNTING NUMBER OF DIGITS IN A NUMBER
DATE:
AIM:
To write a Python program for counting number of digits in a given number.
ALGORITHM:
Step 1 :
Start the program
Step 2 :
Read the value of n
Step 3 :
Assign n1=n
Step 4 :
Initialize count=0
Step 5 :
if (n>0), goto step 6 else goto step 7
Step 6 :
Compute count=count+1
n=n//10, goto step 5
Step 7 : Print the value of count
Step 8 : Stop the program
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for counting number of digits in a given number is written and
output is verified.
EX.NO.: 18
COMPUTING REVERSE OF A NUMBER
DATE:
AIM:
To write a Python program for computing reverse of a given number.
ALGORITHM:
Step 1 :
Start the program
Step 2 :
Read the value of n
Step 3 :
Assign n1=n
Step 4 :
Initialize sum=0
Step 5 :
if (n>0), goto step 6 else goto step 7
Step 6 :
Compute rem=n%10
sum=sum*10+rem
n=n//10, goto step 5
Step 7 : Print the value of sum
Step 8 : Stop the program
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for computing reverse of a given number is written and output is
verified.
EX.NO.:17
PALINDROME NUMBER OR NOT
DATE:
AIM:
To write a Python program to check whether the given number is palindrome or not.
ALGORITHM:
Step 1 :
Start the program
Step 2 :
Read the value of n
Step 3 :
Assign n1=n
Step 4 :
Initialize sum=0
Step 5 :
if (n>0), goto step 6 else goto step 7
Step 6 :
Compute rem=n%10
sum=sum*10+rem
n=n//10, goto step 5
Step 7 : if (sum==n1)
Print n1 is palindrome
else
Print n1 is not palindrome
Step 8 : Stop the program
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program to check whether the given number is palindrome or not is written
and output is verified.
EX.NO.: 16
ARMSTRONG NUMBER OR NOT
DATE:
AIM:
To write a Python program to check whether the given number is Armstrong number or not.
ALGORITHM:
Step 1 :
Start the program
Step 2 :
Read the value of n
Step 3 :
Assign n1=n
Step 4 :
Initialize sum=0
Step 5 :
if (n>0), goto step 6 else goto step 7
Step 6 :
Compute rem=n%10
sum=sum+rem**3
n=n//10, goto step 5
Step 7 : if (sum==n1)
Print n1 is an Armstrong number
else
Print n1 is not an Armstrong number
Step 8 : Stop the program
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program to check whether the given number is Armstrong number or not is
written and output is verified.
EX.NO.:9
FACTORIAL OF A GIVEN NUMBER
DATE:
AIM:
To write a Python program for computing the factorial of a given number.
ALGORITHM:
Step 1 :
Start the program
Step 2 :
Read the value of n
Step 3 :
Initialize fact=1
Step 4 :
for i in range (1,n+1,1) do
compute fact=fact* i
Step 5 : Print the value of fact
Step 6 : Stop the program
PYTHON CODE:
OUTPUT:
RESULT:
Thus the Python program for computing the factorial of a given number is written and output
is verified.