Python Index - CSE
Python Index - CSE
VISWA MAHAVIDYALAYA
(UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956)
ENATHUR, KANCHIPURAM – 631 561
Name :
Reg. No :
Class : II - B.E.(CSE)
BONAFIDE CERTIFICATE
Mr/Ms. ,
Station:
Date:
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
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.
17.
17
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:
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:
Output:
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:
Output:
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:
Program Number:05
Date:
Write a python program to display the largest of 3 integers.
Aim:
Algorithm:
Page | 10
Source code:
Output:
Program Number:06
Date:
Write a python program to demonstrate arithmetic expression.
Aim:
Algorithm:
Page | 12
Source code:
Output:
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:
Program Number:08
Date:
Write a python program to find the factorial of a number.
Aim:
Algorithm:
Page | 16
Source code:
Output:
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:
Program Number:10
Date:
Write a python program to find the area of triangle using Heron’s formula.
Aim:
Algorithm:
Page | 20
Source code:
s = (a + b + c) / 2
Output:
Program Number:11
Date:
Write a python program to check whether the given integer is positive or negative.
Aim:
Algorithm:
Page | 22
Source code:
Output:
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:
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 : "))
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:
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:
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:
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:
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:
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:
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:
Program Number:17
Date:
Write a python program to demonstrate Tuples.
Aim:
Algorithm:
Page | 40
Source code:
Output:
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:
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:
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:
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: "))
print(result)
except ValueError as e:
print("Invalid Input Please Input Integer...")
except ZeroDivisionError as e:
print(e)
Output:
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: