EXPERIMENT – 1
Aim:
To write a program that accepts two integers and prints their sum.
Procedure:
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
Sum=a+b
print ('The two integers are:', a, b)
print ('The sum of two integers are:', Sum)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter the first integer:7
Enter the second integer:3
The two integers are: 7 3
The sum of two integers are: 10
EXPERIMENT – 2
Aim:
To write a Python program that accepts radius of a circle and prints its area.
Procedure:
r = float (input ("Enter radius of circle: "))
a = 3.14159 * r * r
print ("Area of circle =", a)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter radius of circle: 2
Area of circle = 12.56636
EXPERIMENT – 3
Aim:
To write a Python program to accept length and width of a rectangle and
compute its perimeter and area.
Procedure:
l = float (input ("Enter length: "))
w = float (input ("Enter width: "))
print ("Area = “, l*w)
print ("Perimeter = ", 2*(l+w))
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter length: 12
Enter width: 5
Area = 60
Perimeter = 34
EXPERIMENT – 4
Aim:
To write a Python program to compute simple interest for given Principal
amount, time and rate of interest.
Procedure:
p = float (input ("Enter principal: "))
r = float (input ("Enter rate: "))
t = float (input ("Enter time: "))
si = p * r * t / 100
print ("Simple Interest =", si)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter principal: 1000
Enter rate: 5
Enter time: 12
Simple Interest = 600.0
EXPERIMENT – 5
Aim:
To write a Python program to find whether a given number is even or odd.
Procedure:
Num= int(input(“enter number: ”))
If Num%2==0 :
print(“Even Number”)
Else:
Print(“odd number”)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter number: 7
odd number
EXPERIMENT – 6
Aim:
To Write a Python program to find largest among three numbers.
Procedure:
num1=int(input(“enter Number1: ”))
num2=int(input(“enter Number2: ”))
num3=int(input(“enter Number3: ”))
If (num1 >=num2) and (num1>=num3):
Largest=num1
elif (num2>= num1) and (num2>= num3):
Largest =num2
else:
Largest =num3
print(“The largest number is”, Largest)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter Number1: 1
enter Number2: 2
enter Number3: 3
The largest number is 3
EXPERIMENT – 7
Aim:
To write a Python program to perform arithmetic calculation and this
program accepts two operands and an operator then displays the calculated
result.
Procedure:
num1=float (input (“enter Number1: ”))
num2=float (input (“enter Number2: ”))
op=input (“enter Arithmetic operator [+,-,*,/]: ”)
result = 0
if op==’+’:
result= num1+num2
elif op==’-’:
result= num1-num2
elif op==’*’:
result= num1*num2
elif op==’/’:
result= num1/num2
else:
print(“invalid Operator”)
print(num1,op,num2,’=’,result)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter Number1: 3
enter Number2: 3
enter Arithmetic operator [+,-,*,/]: +
3+3=6
EXPERIMENT – 8
Aim:
To write a program which checks if a given year is leap year or not.
Procedure:
Year=int(input(“Enter the year “))
if a%4==0:
Print(“Leap year”)
else:
Print(“Non Leap Year”)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter the year 2024
Leap year
EXPERIMENT – 9
Aim:
To write a Python program to print table of a given number
Procedure:
n=int(input("Enter the number to print the tables for:"))
for i in range(1,11):
print(n,"x",i,"=",n*i)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter the number to print the tables for:4
4x1=4
4x2=8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
EXPERIMENT – 10
Aim:
To write a Python Program to print first n Natural numbers and their sum.
Procedure:
nat_num = int(input("enter the natural number"))
sum = nat_num*(nat_num+1)//2
print("The Total Sum Of",nat_num, "Natural Numbers Is:", sum)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter the natural number3
The Total Sum of 3 Natural Numbers Is: 6
EXPERIMENT – 11
Aim:
To Write a Python Program to accept two integers X and N, compute 𝑋
Procedure:
X = int(input("Enter the base number (X): "))
N = int(input("Enter the exponent (N): "))
result = X **N
print("The result of {X} raised to the power of {N} is:" ,result)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter the base number (X): 2
Enter the exponent (N): 2
The result of 2 raised to the power of 2 is: 4
EXPERIMENT – 12
Aim:
To write a Python Program to calculate factorial of given number using
while loop
Procedure:
number = int(input("Enter a number to calculate its factorial: "))
factorial = 1
counter = 1
while counter <= number:
factorial *= counter
counter += 1
print(f"The factorial of {number} is ",factorial)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter a number to calculate its factorial: 2
The factorial of 2 is 2
EXPERIMENT – 13
Aim:
To write a program to print Fibonacci series
Procedure:
n = int(input("enter the fibonacci series number"))
num1 = 0
num2 = 1
next_number = num2
count = 1
print(num1,num2)
while count <= n:
print(next_number, end=" ")
count += 1
num1, num2 = num2, next_number
next_number = num1 + num2
print()
Result:
Program Executed Successfully
Output (Left Hand Side):
enter the fibonacci series number 2
0112
EXPERIMENT – 14
Aim:
To write a Python program to check whether a given number is equal to the
sum of the cubes of its digits
Procedure:
Num=int(input(“enter a 3 digit number”))
Sum1=0
Temp=Num
while(temp>0):
Digit =temp%10
Sum1+=digit**3
Temp//=10
if(Num==sum1):
print(Num,”is an Armstrong Number”)
else:
print(Num,”is not an armstrong number”)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter a 3 digit number 101
101 is not an armstrong number
EXPERIMENT – 15
Aim:
Write a program to print following pattern on screen.
*
**
***
**
Procedure:
N=3
for I in range(N):
for j in range(N,I+1,-1):
print(‘ ‘,end=’ ‘)
for k in range(I+1):
print(‘* ‘,end=’ ‘)
print()
for I in range(N-1):
for j in range(I+1):
print(‘ ‘,end=’ ‘)
for k in range(N-1,I,-1):
print(‘* ‘,end=’ ‘)
print()
Result:
Program Executed Successfully
Output (Left Hand Side):
**
***
**
EXPERIMENT – 16
Aim:
To write a program to add the odd numbers up to (and including) a given
value N and print the result
Procedure:
n = int (input ("Enter a number: "))
s = 0
for i in range (0, n + 1):
if i%2! = 0:
s = s + i
print (s, "is the sum of all the ODD numbers from 0 to", n)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter a number: 3
4 is the sum of all the ODD numbers from 0 to 3
EXPERIMENT – 17
Aim:
To write a program to compute the greatest common divisor and the least
common multiple of two integers.
Procedure:
num1=int (input ("enter the number1"))
num2=int (input ("enter the number2"))
gcd=1
if(num1%num2==0):
gcd=num2
else:
for k in range(num2//2,1,-1):
if(num1% k==0 and num2%k==0):
gcd=k
break
lcm=(num1*num2)/gcd
print("GCD of two numbers",gcd)
print("LCM of two numbers",lcm)
Result:
Program Executed Successfully
Output (Left Hand Side):
enter the number1 3
enter the number2 2
GCD of two numbers 1
LCM of two numbers 6.0
EXPERIMENT – 18
Aim:
To write a Python program to generate prime numbers for given range
Procedure:
lower = int(input("Enter the start range"))
upper =int(input("Enter the end range"))
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
# all prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter the start range2
Enter the end range4
Prime numbers between 2 and 4 are:
2
3
EXPERIMENT – 19
Aim:
To write a Python Program to check whether the given string is palindrome
or not.
Procedure:
g=input("Enter string:")
if(g==g[::-1]):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")
Result:
Program Executed Successfully
Output (Left Hand Side):
Enter string:racecar
The string is palindrome
EXPERIMENT – 20
Aim:
To write a Python program to sort a list of 10 numbers using Bubble Sort
method.
Procedure:
arr=[7,3,2,1,5,4,6]
n=len (arr)
for i in range(n):
for j in range(n-1):
if(arr[j]> arr[j+1]):
temp=arr[j]
arr[j]=arr[j+1]
arr[j+1]=temp
for i in range(n):
print(arr[i],end=' ')
Result:
Program Executed Successfully
Output (Left Hand Side):
1234567
EXPERIMENT – 21
Aim:
To write a Python program to sort a list of 10 numbers using Insertion Sort
method.
Procedure:
arr=[7,3,2,1,5,4,6]
n=len(arr)
for i in range(n):
key=arr[i]
j=i-1
while j>=0 and key <arr[j]:
arr[j+1]=arr[j]
j=j-1
arr[j+1]=key
for i in range(n):
print(arr[i],end=' ')
Result:
Program Executed Successfully
Output (Left Hand Side):
1234567
EXPERIMENT – 22
Aim:
To learn 2 SQL Commands (CREATE and DROP)
Procedure:
1.CREATE It is used to create a new table in the database.
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHA
R2(100), DOB DATE);
2. DROP: It is used to delete both the structure and record
stored in the table
Syntax:
DROP TABLE ;
Example:
DROP TABLE EMPLOYEE;
Result:
Executed Sucessfully.