SRI CHANDRASEKHARENDRA SARASWATHI
VISWA MAHAVIDYALAYA
(UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956)
ENATHUR, KANCHIPURAM – 631 561
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
PYTHON PROGRAMMING LABORATORY RECORD
Name :
Reg. No :
Class : II - B.E.(CSE)
Subject : BCSF183P80 –Python Programming Lab
SRI CHANDRASEKHARENDRA SARASWATHI
VISWA MAHAVIDYALAYA
(UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956)
ENATHUR, KANCHIPURAM – 631 561
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
BONAFIDE CERTIFICATE
This is to certify that this is the bonafide record of work done by
Mr/Ms. ,
with Reg. No of II-B.E.(CSE) in the Python
Programming Lab (BCSF183P80) during the academic year 2022 – 23.
Station:
Date:
Staff-in-charge Head of the Department
Submitted for the Practical examination held on .
Examiner1 Examiner 2
INDEX
Page Staff
S.No. Date Title
No. Initials
Write a Python Program to demonstrate various
datatypes in python.
1.
Write a Python Program to calculate the age by
taking year of birth as input.
2.
Write a Python Program to compute your weight
in pounds by accepting your weight in kilogram
3. using input function.
Write a Python Program to create, concatenate
and accessing sub string and print the given string.
4.
Write a Python Program to display the largest of 3
integers.
5.
Write a Python Program to demonstrate arithmetic
expression.
6.
Write a Python Program to convert weight from
kg to pound and pound to kg.
7.
Write a Python Program to find the factorial of a
number.
8.
Write a Python Program to find the area of circle.
9.
Write a Python Program to find the area of
triangle using Heron’s formula.
10.
Write a Python Program to check whether the
given integer is positive or negative.
11.
Write a Python Program to check whether the
given number is even or odd.
12.
11
Write a Python Program to create, append and
remove list in python.
13.a
Page | 0
Page Staff
S.No. Date Title
No. Initials
Write a Python Program to sort and reverse the
list.
13.b
Write a Python Program to find the counting and
the occurrence of the item in the list and check for
13.c its existence.
Write a Python Program to print Fibonacci series.
14.
Write a Python Program to remove duplicate
items from the list.
15.a
Write a Python Program to print the letter “L”
using ‘*’.
15.b
15.
Write a Python Program to perform matrix
addition using 2D list.
16.
Write a Python Program to demonstrate Tuples.
17.
17
Write a Python Program to demonstrate
Dictionaries.
18.
Write a Python Program to add two numbers of
different data types by using functions.
19.a
Write a Python Program to find the sum of digits
in the number using functions.
19.b
Write a Python Program to code to implement
value error and division error.
20.
Write a python code to display student
information using class and object.
21.
Page | 1
Program Number: 01
Date:
Write a python program to demonstrate various datatypes in python.
Aim:
Algorithm:
Page | 2
Source code:
a=5
print("The type of a", type(a))
b = 40.5
print("The type of b", type(b))
c = 1+3j
print("The type of c", type(c))
d=True
print(“The type of d” ,type(d))
Output:
Result: The code has been executed successfully.
Page | 3
Program Number:02
Date:
Write a python program to calculate the age by taking year of birth as input.
Aim:
Algorithm:
Page | 4
Source code:
a=input("Enter current year=")
b=input("Enter your year of birth=")
c=int(a)-int(b)
print(c)
Output:
Result: The code has been executed successfully.
Page | 5
Program Number:03
Date:
Write a python program to compute your weight in pounds by accepting your
weight in kilogram using input function.
Aim:
Algorithm:
Page | 6
Source code:
kg = input("Enter the weight in KG ")
pounds = float(kg) * 2.2
print(“The weight in pounds is=”,pounds)
Output:
Result: The code has been executed successfully.
Page | 7
Program Number:04
Date:
Write a python program to create, concatenate and accessing sub string and print
the given string.
Aim:
Algorithm:
Page | 8
Source code:
s1=input("Enter first String : ");
s2=input("Enter second String : ");
print("First string is : ",s1);
print("Second string is : ",s2);
print("concatenations of two strings :",s1+s2);
print("Substring of given string :",s1[1:4]);
Output:
Result: The code has been executed successfully.
Page | 9
Program Number:05
Date:
Write a python program to display the largest of 3 integers.
Aim:
Algorithm:
Page | 10
Source code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
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)
Output:
Result: The code has been executed successfully.
Page | 11
Program Number:06
Date:
Write a python program to demonstrate arithmetic expression.
Aim:
Algorithm:
Page | 12
Source code:
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
sum = float(num1) + float(num2)
min = float(num1) - float(num2)
mul = float(num1) * float(num2)
div = float(num1) / float(num2)
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min))
print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul))
print('The division of {0} and {1} is {2}'.format(num1, num2, div))
Output:
Result: The code has been executed successfully.
Page | 13
Program Number:07
Date:
Write a python program to convert weight from kg to pound and pound to kg.
Aim:
Algorithm:
Page | 14
Source code:
opt=input("1.Convert Kg to Pounds.\n2.Convert Pounds to Kg\n Enter Option = ")
if(int(opt)==1):
kilo = float (input('Enter weight in Kg to Convert into pounds:'))
pounds = kilo * 2.2046
print("weight in pounds =",pounds)
elif(int(opt)==2):
pounds= float(input('Enter weight in pounds to Convert into kg:'))
kilo = pounds/2.2046
print("weight in kilo =",kilo)
else:
print("Invalid option")
Output:
Result: The code has been executed successfully.
Page | 15
Program Number:08
Date:
Write a python program to find the factorial of a number.
Aim:
Algorithm:
Page | 16
Source code:
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial))
Output:
Result: The code has been executed successfully.
Page | 17
Program Number:09
Date:
Write a python program to find the area of circle.
Aim:
Algorithm:
Page | 18
Source code:
import math
def area(r):
area = math.pi* pow(r,2)
return print('Area of circle is:' ,area)
a=input ("Enter circle radius=")
area(int(a))
Output:
Result: The code has been executed successfully.
Page | 19
Program Number:10
Date:
Write a python program to find the area of triangle using Heron’s formula.
Aim:
Algorithm:
Page | 20
Source code:
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
s = (a + b + c) / 2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print(“The area of the triangle is”,area)
Output:
Result: The code has been executed successfully.
Page | 21
Program Number:11
Date:
Write a python program to check whether the given integer is positive or negative.
Aim:
Algorithm:
Page | 22
Source code:
num = float(input("Input a number: "))
if num > 0:
print("It is positive number")
elif num == 0:
print("It is Zero")
else:
print("It is a negative number")
Output:
Result: The code has been executed successfully.
Page | 23
Program Number:12
Date:
Write a python program to check whether the given number is even or odd.
Aim:
Algorithm:
Page | 24
Source code:
num = int (input ("Enter any number to test whether it is odd or even: "))
if num==0:
print("The value is 0")
elif (num % 2) == 0:
print ("The number is even")
elif(num%2)==1:
print ("The provided number is odd")
else:
print("Invalid input")
Output:
Result: The code has been executed successfully.
Page | 25
Program Number: 13.a
Date:
Write a python program to create, append and remove list in python.
Aim:
Algorithm:
Page | 26
Source code:
lst = []
n = int(input("Enter number of elements : "))
for i in range(0, n):
ele = int(input())
lst.append(ele)
print(lst)
z=int(input("Enter number of elements to remove : "))
for y in range(0,z):
a=int(input("Enter element to remove : "))
lst.remove(int(a))
print(lst)
Output:
Result: The code has been executed successfully.
Page | 27
Program Number: 13.b
Date:
Write a python program to sort and reverse the list.
Aim:
Algorithm:
Page | 28
Source code:
lst = [1, 6, 5, 2, 7, 9]
lst.sort()
print(“Ascending order of list=”,lst)
lst.reverse()
print("Using reverse() ", lst)
print("Using reversed() ", list(reversed(lst)))
Output:
Result: The code has been executed successfully.
Page | 29
Program Number:13.c
Date:
Write a python program to find the counting and the occurrence of the item in the
list and check for its existence.
Aim:
Algorithm:
Page | 30
Source code:
Lst=['a','b','c','a','a','c']
print("The occurence of a in list is",Lst.count("a"))
print("The occurence of b in list is",Lst.count("b"))
print("The occurence of c in list is",Lst.count("c"))
Output:
Result: The code has been executed successfully.
Page | 31
Program Number:14
Date:
Write a python program to print Fibonacci series.
Aim:
Algorithm:
Page | 32
Source code:
#fibonaci series
i=0
n=1
for c in range(0,20):
r=i+n
i=n
n=r
print(r)
Output:
Result: The code has been executed successfully.
Page | 33
Program Number:15.a
Date:
Write a python program to remove duplicate items from the list.
Aim:
Algorithm:
Page | 34
Source code:
a = [1,1,2,3,2,2,4,5,6,2,1]
print("List before removing duplicate items\n",list(a))
b = set(a)
print("List after removing duplicate items\n",list(b))
Output:
Result: The code has been executed successfully.
Page | 35
Program Number:15.b
Date:
Write a python program to print the letter “L” using ‘*’.
Aim:
Algorithm:
Page | 36
Source code:
number=[1,1,1,1,6]
for x in number:
output=''
for count in range(x):
output+='*'
print(output)
Output:
Result: The code has been executed successfully.
Page | 37
Program Number:16
Date:
Write a python program to perform matrix addition using 2D list.
Aim:
Algorithm:
Source code:
m1=[
[1,2,3],
[4,5,6],
[7,8,9]
]
print(m1)
m2=[
[1,1,1],
[1,1,1],
[1,1,1]
]
print(m2)
result=[
[0,0,0],
[0,0,0],
[0,0,0]
]
Page | 38
for i in range(len(m1)):
for j in range(len(m1[0])):
result[i][j]=m1[i][j]+m2[i][j]
print(" ")
print(result)
Output:
Result: The code has been executed successfully.
Page | 39
Program Number:17
Date:
Write a python program to demonstrate Tuples.
Aim:
Algorithm:
Page | 40
Source code:
Tuple1 = ('1', '2',’3’,’4’,’5’,’Hello’)
print("\nTuple with the use of String: ")
print(Tuple1)
Output:
Result: The code has been executed successfully.
Page | 41
Program Number:18
Date:
Write a python program to demonstrate Dictionaries.
Aim:
Algorithm:
Page | 42
Source code:
Dict={}
n=int(input("Enter the number of elements in list="))
b=1
for z in range(0,n):
a=int(input("Enter elements ="))
Dict[b] = a
print(Dict)
b+=1
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
print("\n\n")
x=int(input("Enter number of elements to be deleted="))
for y in range(0,x):
m=int(input("Enter element's index to be deleted in the list="))
Dict.pop(int(m))
print(Dict)
Output:
Result: The code has been executed successfully.
Page | 43
Program Number:19. a
Date:
Write a python program to add two numbers of different data types by using
functions.
Aim:
Algorithm:
Page | 44
Source code:
def add_num(a,b):
sum=a+b;
return sum;
num1=float(input("input the number one: "))
num2=float(input("input the number one: "))
print("The sum is",add_num(num1,num2))
Output:
Result: The code has been executed successfully.
Page | 45
Program Number:19.b
Date:
Write a python program to find the sum of digits in the number using functions.
Aim:
Algorithm:
Page | 46
Source code:
def getSum(n):
sum = 0
for digit in str(n):
sum += int(digit)
return sum
n = 12345
print(getSum(n))
Output:
Result: The code has been executed successfully.
Page | 47
Program Number:20
Date:
Write a python program to implement value error and division error.
Aim:
Algorithm:
Page | 48
Source code:
try:
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 / num2
print(result)
except ValueError as e:
print("Invalid Input Please Input Integer...")
except ZeroDivisionError as e:
print(e)
Output:
Result: The code has been executed successfully.
Page | 49
Program Number: 21
Date:
Write a python code to display student information using class and object.
Aim:
Algorithm:
Page | 50
Source code:
class Student:
def getStudentDetails(self):
self.rollno=input("Enter Roll Number : ")
self.name = input("Enter Name : ")
self.physics =int(input("Enter Physics Marks : "))
self.chemistry = int(input("Enter Chemistry Marks : "))
self.maths = int(input("Enter Math Marks : "))
def printResult(self):
self.percentage = (int)( (self.physics + self.chemistry + self.maths) / 300 * 100
);
print("Student name =",self.name)
print("Student roll number =",self.rollno)
print("Percentage aquired =",self.percentage)
S1=Student()
S1.getStudentDetails()
print("Result : ")
S1.printResult()
Output:
Result: The code has been executed successfully.