0% found this document useful (0 votes)
2 views44 pages

Python Record

Uploaded by

Aarthi mukesh M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views44 pages

Python Record

Uploaded by

Aarthi mukesh M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

G.

VENKATASWAMY NAIDU COLLEGE (SFC), KOVILPATTI


(An Autonomous Institution | Affiliated to Manonmaniam Sundaranar
University) (Re-Accredited with “A” Grade by NAAC | DBT Star College
Status)

Record of Programming with Python work in

III [Link]. (Information Technology)

Register No:
Subject Code: U21IT6P8

This is certified to be the Bonafide Record of the work done by

of III [Link]. (Information Technology).

STAFF IN CHARGE HEAD OF THE DEPARTMENT

Submitted for the practical examination held on at

G. Venkataswamy Naidu College, Kovilpatti.

INTERNAL EXAMINER EXTERNAL EXAMINER

PLACE:

DATE:
INDEX

[Link] DATE PROGRAM NAME [Link] SIGNATURE


1. 05/12/2024 Write a python program that reads a
Celsius degree from the console and
converts into Fahrenheit and displays the
result.
2. 09/12/2024 Write a program to demonstrate different
number data types in python.
3. 17/12/2024 Write a program to perform different
arithmetic operations on numbers in python.
4. 24/12/2024 Write a program to create, concatenate and
print a string and accessing sub-string from
given string.
5. 09/01/2025 Write a program to create, append and
remove lists in python.
6. 20/01/2025 Write a python program linear search.
7. 28/01/2025 Write a python program selection sort.
8. 05/02/2025 Write a python program merge sort.

9. 10/02/2025 Write a python program to define a module


to find Fibonacci numbers and import the
module to another program.
10. 03/03/2025 Write a python program to demonstrate
inheritance.
11. 05/03/2025 Write a python code demonstrate method
overloading.
12. 10/03/2025 Write a program to demonstrate method
overriding.
13. 18/03/2025 Write a python program that inputs a text
file the program should print of all the
unique words in the file in alphabetical.
[Link] DATE: 05/12/2024

Temperature Conversion

AIM:
To Write a python program that Converts Celsius degree into Fahrenheit and
displays the result.

ALGORITHM:

 Start
 Input Fahrenheit value (f)
 Input Celsius value (c)
 Convert Fahrenheit to Celsius using the formula: a=(f−32)×5/9
 Print Fahrenheit value and its Celsius equivalent (a)
 Convert Celsius to Fahrenheit using the formula: b=(c×9/5)+32
 Print Celsius value and its Fahrenheit equivalent (b)
 End
Program:

print ("convert temperature")

c=float (input ("enter Celsius value:"))

f=float (input ("enter Fahrenheit

value:")) a=(f-32) *5/9

print ("Fahrenheit to Celsius:",a)

b=c*9/5+32

print("Celsius to Fahrenheit:",b)
OUTPUT:

convert temperature

enter Celsius value:50.56

enter Fahrenheit value:126.58

Fahrenheit to Celsius:

52.544444444444444 Celsius to

Fahrenheit: 123.00800000000001

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:09/12/2024

Data Type

AIM:
To Write a program to demonstrate different number of data types in python.

ALGORITHM:

 Start
 Create a class Sum and Define data() method.
 Take integer inputs a and b and floating-point inputs d and e
 Define add() method and compute c = a + b and print c and its data type
 Define mul() method and compute f = d * e and print f and its data type
 Create a subclass NewSum that inherits Sum
 Create an object s of NewSum
 Call data() , add() and mul() method
 End
Program:

class Sum:

def data(self):

self.a = int(input("Enter a number: ")) self.b

= int(input("Enter b number: ")) self.d =

float(input("Enter d number: ")) self.e =

float(input("Enter e number: ")) def

add(self):

c = self.a + self.b

print("datatye of a:", type(self.a))

print("datatye of b:", type(self.b))

print("add:",c,"datatype",type(c))

def mul(self):

f = self.d * self.e

print("datatye of d:", type(self.d))

print("datatye of e:", type(self.e))

print("sub:",f,"datatype", type(f))

class NewSum(Sum):

pass s = NewSum() [Link]()

[Link]()

[Link]()
OUTPUT:

Enter a number: 56

Enter b number: 55

Enter d number: 36.1

Enter e number: 71.135

datatye of a: <class

'int'> datatye of b:

<class 'int'>

add: 111 datatype <class

'int'> datatye of d: <class

'float'> datatye of e: <class

'float'>

sub: 2567.9735000000005 datatype <class 'float'>

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:17/12/2024

Arithmetic Operations

AIM:

To Write a program to perform different arithmetic operations on given


number in python.

ALGORITHM:

 Start
 Input values:
 Prompt the user to enter integer values for a and b.
 Define functions:
 add(a, b): Return the sum of a and b.
 sub(a, b): Return the difference of a and b.
 mul(a, b): Return the product of a and b.
 div(a, b): Return the quotient of a divided by b.
 mod(a, b): Return the remainder of a divided by b.
 flrdiv(a, b): Return the result of floor division between a and b.
 exp(a, b): Return the result of a raised to the power of b.
 Call functions to perform and print:
 Addition, Subtraction, Multiplication, Division, Modulus,
Floor division, Exponentiation.
 End
Program:
a=int(input("enter value for a:"))

b=int(input("enter value for b:"))

def add(a,b):
return a+b;

print("Addition Result:",add(a,b))

def sub(a,b):
return a-b;

print("subtraction Result:",sub(a,b))

def mul(a,b):
return a*b;

print("multipication Result:",mul(a,b))

def div(a,b):
return a/b;

print("division Result:",div(a,b))

def fdiv(a,b):
return a//b;

print("floordivision Result:",fdiv(a,b))

def mod(a,b):
return a%b;

print("modulo Result:",mod(a,b))

def exp(a,b):
return a**2;
print("expotential Result:",exp(a,b))
OUTPUT:

Enter value for a:45

Enter value for b:58

Addition Result: 103

Subtraction Result: -13

Multiplication Result: 2610

Division Result: 0.7758620689655172

Floor division Result: 0

Modulo Result: 45

Exponential Result: 2025

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:24/12/2024

String Program

AIM:
To Write a python program to create, concatenate and print a given string.

ALGORITHM:

 Start
 Take str1 and str2 as input.
 Concatenate str3 = str1 + str2 and print in different formats.
 Then [Link](',') and print.
 Print slices of str3 (str3[2:6], str3[3:6], str3[:1]).
 Find str3 substring after asking for substring input.
 Print str3[2], [Link]('a'), and [Link]('').
 Check if [Link]('t') and [Link]('y').
 Print [Link](), [Link](), and check if [Link]() or [Link]().
 End
Program:

str1=input("enter the string1:")


str2=input("enter the string2:")
print("string 3--")
str3=str1+str2
print(str1+str2)
print(str3)
print("string concatenation using join: " + " ".join([str1,str2])) print("split:",[Link](","))
print("str3 from 3 to 6:",str3[3:6])
print("str3 from 2 to 6:",str3[2:6])
print("str3 from 0 to 1:",str3[0:1])
print([Link](input("enter the substring to find from str3:"))) print("the
second letter in str3 is:"+str3[2])
print("count a:",[Link]('a')) print("count
letters:",[Link](''))
print("lowercase:",[Link]())
print("uppercase:",[Link]())
print("islower:",[Link]())
print("string length:",len(str3))
print("sad" in str3)
if "sad" in str3:
print("yes, 'sad' is present.")
if "lii" not in str3:
print("yes, 'lii' not is present.")
OUTPUT:
enter the string1:sree
enter the string2:sadhu
string 3--
sreesadhu
sreesadhu
sreesadhu
string concatenation using join: sree sadhu
split: ['sreesadhu']
str3 from 3 to 6: esa
str3 from 2 to 6: eesa
str3 from 0 to 1: s
enter the substring to find from str3:sad
4
the second letter in str3 is: e
count a: 1
count letters: 10
lowercase: sreesadhu
uppercase: SREESADHU
islower: True
string length: 9
True
yes, 'sad' is present.
yes, 'lii' not is
present.

RESULT:
Thus, the program was executed successfully and the output was verified.
[Link] DATE:09/01/2025

List Program

AIM:
To Write a program that create, append and remove lists in python.

ALGORITHM:

 Start
 Creates and prints lists
 Converts a string into a list of characters
 Retrieves specific elements using indexing, including from nested lists.
 Appending (append()) → Adds an element to the end.
 Removing (remove()) → Deletes a specific element.
 Extending (extend()) → Adds multiple elements at once.
 Popping (pop()) → Removes and returns the last element.
 Sorting (sort()) → Arranges elements in ascending order.
 Reversing (reverse()) → Reverses the order of elements.
 Inserting (insert(index, value)) → Adds an element at a specific position.
 End
Program:

mylist=[] mylist=["python","c+

+","c","java"]

print("languages:",mylist)

nested=['anitha',[1,4,6],['priya']]

print("nestedlist--",nested)

print(list('anitha'))

mylist2=['ani','sree','priya','sadhu']

print("mylist[0]--",mylist[0])

print("mylist[1]--",mylist[1])

print("mylist[3]--n",mylist[3]) list2=['anitha',

[1,2,3,4],[6,7,8,9]]

print("list2[0][2]--",list2[0][2])

print("list2[1][2]--",list2[1][2])

print("list2[2][2]--",list2[2][2])

mylist3=[1,3,4,5,6]

print("mylist3--",mylist3)

[Link]('d')

print("append--",mylist3)

[Link](5)

print("remove--",mylist3)

[Link]([1,5,6])
print("extend--",mylist3)

[Link]()

print("pop--",mylist3)

list=['sadhana','anitha','priya']

[Link]()

print("sort--",list)

[Link](2,'sughi')

print("insert--",list)

[Link]()

print("reverse--",list)
OUTPUT:

languages: ['python', 'c++', 'c', 'java']

nestedlist-- ['anitha', [1, 4, 6], ['priya']]

['a', 'n', 'i', 't', 'h', 'a']

mylist[0]-- python

mylist[1]-- c++

mylist[3]--n java

list2[0][2]-- i

list2[1][2]-- 3

list2[2][2]-- 8

mylist3-- [1, 3, 4, 5, 6]

append-- [1, 3, 4, 5, 6, 'd']

remove-- [1, 3, 4, 6, 'd']

extend-- [1, 3, 4, 6, 'd', 1, 5, 6]

pop-- [1, 3, 4, 6, 'd', 1, 5]

sort-- ['anitha', 'priya', 'sadhana']

insert-- ['anitha', 'priya', 'sughi', 'sadhana']

reverse-- ['sadhana', 'sughi', 'priya', 'anitha']

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:20/01/2025

Linear Search

AIM:
To write a python program for demonstrate in linear search.
.

ALGORITHM:

 Start with the first element in the list.

 Find the smallest element in the unsorted portion of the list (starting from

the current element).

 Swap the smallest element found with the current element.

 Move the current element one step forward and repeat the process for the

next element, until the entire list is sorted.

 The list will be sorted in ascending order by the end of the loops.
Program:

mylist = []
n = int(input("enter an element:"))
for i in range(0, n):
a = int(input("enter a number:"))
[Link](a)
print(mylist)

n1 = int(input("enter a number:")) if
n1 in mylist:
print("available")
else:
print("not found")
OUTPUT:

enter an

element:4 enter a

number:9 enter a

number:5 enter a

number:8 enter a

number:2 [9, 5, 8,

2]

enter a number:5

available

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:28/01/2025

Selection Sort

AIM:
To Write a program to sorting the given element in python.

ALGORITHM:

 Start with the first element in the list.


 Find the smallest element in the unsorted portion of the list (starting from the
current element).
 Swap the smallest element found with the current element.
 Move the current element one step forward and repeat the process for the next
element, until the entire list is sorted.
 The list will be sorted in ascending order by the end of the loops.
Program:

n=[]
l=int(input("Enter the no of element of list:"))

for i in range(0,l): n1=int(input("Enter


the element:")) [Link](n1)
print("Element of list:",n)
size=len(n)
for j in range(0,size): min=j
for i in range(j+1,size):

if n[i] < n[min]:


min= i
(n[j], n[min]) = (n[min], n[j])

[Link]()

print("sort list:",n)
OUTPUT:

Enter the no of element of

list:5 Enter the element:9

Enter the element:2

Enter the

element:7 Enter

the element:0

Enter the

element:3

Element of list: [9, 2, 7, 0, 3]

sort list: [0,2,3,7,9]

RESULT:
Thus, the program was executed successfully and the output was verified.
[Link] DATE:05/02/2025

Merge Sort

AIM:
To Write a python program for merging and sorting the given element.

ALGORITHM:

 Start
 The user is prompted to enter the number of elements in the first list.
 The user then enters each element one by one, which is added to list a.
 The same process is repeated for the second list, and the elements are added list b.
 Similarly, the third list is populated with elements entered by the user and
stored in list c.
 The new list (containing elements from all three lists) is sorted in ascending order.
 The sorted list is printed.
 End
Program:

a=[]
b=[]
c=[]
print("list 1")
n=int(input("enter an element:")) for i
in range(0,n):
d=int(input("enter a number:"))
[Link](d)
print("elements",a)
print("********")
print("list 2")
n1=int(input("enter an
element:")) for j in range(0,n1):
e=int(input("enter a number:"))
[Link](e)
print("elements",b)
print("********")
print("list 3")
n2=int(input("enter an element:")) for
k in range(0,n2):
f=int(input("enter a number:"))
[Link](f)
print("elements",c)
new=a+b+c
[Link]()
print("sorting a numbers:",new)
OUTPUT:

list 1
enter an element:4
enter a number:9
enter a number:2
enter a number:7
enter a number:6
elements [9, 2, 7,
6]
********
list 2
enter an
element:3 enter a
number:6 enter a
number:7 enter a
number:9
elements [6, 7, 9]
********
list 3
enter an element:4
enter a number:5
enter a number:9
enter a number:1
enter a number:7
elements [5, 9, 1,
7]
sorting a numbers: [1, 2, 5, 6, 6, 7, 7, 7, 9, 9, 9]

RESULT:
Thus, the program was executed successfully and the output was verified.
[Link] DATE:10/02/2025

Fibonacci Series

AIM:
To Write a python program to define a module to find Fibonacci numbers
and import the module to another program.

ALGORITHM:

 Start.
 The first two terms of the Fibonacci series are set as n1 = 0 and n2 = 1.
 The user is asked to enter a number n, which determines how many
Fibonacci numbers should be printed.
 The first two Fibonacci numbers (0 and 1) are printed immediately.
 Starting from the 3rd term (index 2), the next Fibonacci number is
calculated by summing the previous two numbers (n1 and n2).
 The new number (n3) is printed, and the values of n1 and n2 are updated
for the next iteration (n1 = n2 and n2 = n3).
 The loop continues until n Fibonacci numbers have been printed.
 End.
Program:

[Link]

def fib():
n1=0
n2=1
n=int(input("enter a number:"))
print(n1)
print(n2)
for i in range(2,n,1):
n3=n1+n2
print(n3)
n1=n2
n2=n3

[Link]

import fibo [Link]()


OUTPUT:

enter a number:5

0
1
1
2
3

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:03/03/2025

Inheritance

AIM:
To Write a python program to demonstrate the classes for using inheritance.

ALGORITHM:

 Start
 The get() method is called on the obj object to input the student's name,
age, and marks for three subjects.
 The cal() method is called to calculate the total marks by adding the marks
of the three subjects, and the average is calculated by dividing the total by 3.
 The tot (total) and avg (average) are returned.
 The put() method is called with the tot and avg as arguments to print
the student's name, age, marks, total, and average
 End
Program:

class stu:
def getdata(self):
self.a=input("enter name:")
self.b=int(input("entre age:"))
self.m1=int(input("mark1:"))
self.m2= int(input("mark2:"))
self.m3= int(input("mark3:"))
def cal(self):
tot= self.m1+self.m2+self.m3
avg=tot/3
return tot,avg
def display(self,tot,avg):
print("student details")
print("student name:", self.a)
print("student age:", self.b)
print("mark1:", self.m1)
print("mark2:", self.m2)
print("mark3:", self.m3)
print("total:",tot)
print("average:",avg)
class newstu(stu):
pass
obj=newstu() [Link]()
tot,avg=[Link]()
[Link](tot,avg)
OUTPUT:

enter name: anu


entre age:23
mark1:98
mark2:95
mark3:94
student details
student name:
anu student age:
23
mark1: 98
mark2: 95
mark3: 94
total: 287

average: 95.66666666666667

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:05/03/2025

Method Overloading

AIM:
To Write a python code for demonstrate same functions using in method
overloading..

ALGORITHM:

 Start
 Define a class num.
 Implement a single add method that:
 Checks the data type of the input parameters.
 If both are integers or floats, return their sum.
 If both are strings, concatenate them.
 Otherwise, return an error message.
 Create an instance of the class and test with different inputs.
 End
Program:

class num:
def add(a=0, b=0):
return a+b
def add(a=0.0, b=0.0):
return a+b
def add(a="sadhana ", b="selvi "):
return a+b
n=num
print([Link](20,5))
print([Link](3,4.5))
print([Link]())
OUTPUT:

25

7.5

sadhana selvi

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:10/03/2025

Method Overriding

AIM:
To Write a program to demonstrate for using method overriding in python.

ALGORITHM:

 Start
 Define the Parent Class:
 Create a class named Parent.
 Define a method greet() that returns the string "This is from Parent class".
 Define the Child Class (Inheritance):
 Create a class named Child that inherits from Parent.
 Override the greet() method.
 Inside greet(), call super().greet() to get the Parent class method result.
 Concatenate the returned string with " and This is from child class"
and return the new string.
 Create an Object of the Child Class:
 Instantiate an object c of the Child class.
 Call the greet() Method on the Child Object:
 Call [Link]() and print the result.
 End
Program:

class Parent:

def greet(self):

return "This is from Parent class"

class Child(Parent):

def greet(self):

super().greet()

return f"{super().greet()} and This is from child class" c

= Child()

print([Link]())
OUTPUT:

This is from Parent class and This is from child class

RESULT:

Thus, the program was executed successfully and the output was verified.
[Link] DATE:18/03/2025

File Program

AIM:
To Write a python program that inputs a text file the program should print
of all the unique words in the file in alphabetical.

ALGORITHM:

 Start
 Open the File and Reads the content of [Link] into a string.
 Converts all text to lowercase for case-insensitive comparison.
 Splits the text into individual words.
 Removes punctuation and possessive 's suffixes.
 Collects unique words by ensuring no duplicates.
 Sorts the unique words alphabetically.

 Outputs the sorted list of unique words

 End
Program:

text=open("[Link]","r")
text=[Link]()
text=[Link]()
words=[Link]()
words=[[Link](',.!;()[]')for word in words]
words=[[Link]("s",'')for word in
words] uni=[]
for word in words: if
word not in uni:
[Link](word)
[Link]()
print(uni)

[Link]
Hello

selvi]

hii's

what?

go

how!
OUTPUT:

['elvi', 'go', 'hello', "hii'", 'how', 'what?']

RESULT:

Thus, the program was executed successfully and the output was verified.

You might also like