Shakthi Py-record 12
Shakthi Py-record 12
24 08-09-2023 Add the getter and setter method for the following class to 24
change the values of variables name and age which are
private.Create an object of the class to invoke the methods
32 03-04-2023 Develop a python program to check the given UID valid or not 32
according to the specified rules.
47 02-06-2023 List out the candidates appeared for the interview anddisplay 50
the slot (or) position of third candidate.
Step-1: Start.
Step-3: Add the two complex numbers by using another variable and print the program.
Step-4: Stop.
PROGRAM:
c1=4+2j
c2=5+3j
c3=c1+c2
print(c3)
OUTPUT:
RESULT:
Thus the PROGRAM to add the complex numbers has executed successfully.
EX NO- 1B DATE:
Write a python program to read one string and integer and print the values
AIM:
To write a python program to read one string and integer and print the values.
ALGORITHM:
Step-1: Start.
Step-3: Prompt the user to input another value and store it in variable b.
Step-5: Stop.
PROGRAM:
a = input()
b = input()
print(a,b)
OUTPUT:
RESULT:
Thus the PROGRAM to print the float numbers using format() has executed successfully.
EXP NO- 1C DATE:
Write a python program to find rate of interest based on the user given principle, time & SI.
AIM:
To write a python program to find rate of interest based on the user given principle, time & SI.
ALGORITHM:
Step-1: Start.
Step-2: We prompt the user to input these values using the input function, and we evaluate the input
using eval to convert it to the appropriate data type.
Step-3: We calculate the rate of interest r using the formula si * 100 / (p * t). This formula calculates the
rate of interest based on the given values of principal amount, time, and simple interest.
Step-4: Finally, we use the print function to display the calculated rate of interest. The "{:.2f}"
format specifier formats the value of r to two decimal places for better readability.
Step-5: Stop.
PROGRAM:
p = eval(input())
t = eval(input())
si = eval(input())
r=si*100/(p*t)
print("Rate of Interest : {:.2f}".format(r))
OUTPUT:
RESULT:
Thus the code print the time taken by the car has executed successfully.
DATE:
EXP NO- 1D
Write a python program to read one string and integer and print the values.
AIM:
To write a python program to read one string and integer and print the values
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
t= eval(input())
if t > 97:
print("The person has fever")
OUTPUT:
RESULT:
Thus the Code to check whether the number is even or odd has executed successfully.
EXP NO- 2A DATE:
Write a Python Program to print numbers range from M to N (including M and N values).
AIM:
To write Python Program to print numbers range from M to N (including M and N values).
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
m=int(input())
n=int(input())
for i in range(n,m-1,-1):
if i%11 ==0:
print(i)
OUTPUT:
RESULT:
Thus the Code to print M to N which are divisible by 11 has executed successfully.
EXP NO- 2B DATE:
Write a Python program to print the even numbers from a given list.
AIM:
To Write a python program to print the even numbers from a given list.
ALGORITHM:
Step-1: Start.
Step-4: Using format function and loops return the even num by using if else concept.
Step-5: Stop.
PROGRAM:
` def is_even_num(l):
` enum = []
` for n in l:
` if n % 2 == 0:
` enum.append(n)
` return enum
OUTPUT:
RESULT:
Thus the Code to return the even numbers from a given list has executed successfully.
EXP NO- 2C DATE:
Write a python program to print the quotient and remainder of the division on the given numbers
using built in fun divmod()
AIM:
To write a python program to print the quotient and remainder of the division on the given
numbers using built in fun divmod()
ALGORITHM:
Step-1: Start.
Step-4: Store the inputs in built in function and print the result.
Step-5: Stop.
PROGRAM:
x=int(input())
y=int(input())
z=divmod(x,y)
print(z)
OUTPUT:
RESULT:
Thus the Code to find the divmod() of two numbers has executed successfully.
EXP NO- 2D DATE:
Create a Python program to print the simple star pattern using a for loop.
AIM:
To Create a Python program to print the simple star pattern using a for loop.
ALGORITHM:
Step-1: Start.
Step-4: Inside the for loop give another loop for j in range of i and print “*”.
Step-5: Stop.
PROGRAM:
rows=int(input())
for i in range(1,rows):
for j in range(i):
print(“*”,Stop=" ")
print("")
OUTPUT:
RESULT:
Thus the Code to print the simple number pattern has executed successfully.
EXP NO- 3A DATE:
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
a=input()
print(f"The length of the string '{a}' is {len(a)}")
OUTPUT:
RESULT:
Thus the Code to find the length of string using built in function has executed successfully.
EXP NO- 3B DATE:
Write a Python program to find sequences of lowercase letters joined with a underscore.
AIM:
To Write a Python program to find sequences of lowercase letters joined with a underscore.
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
import re
t=input()
x=re.search("[a-z]+_+[a-z]",t)
if x:
print("Found a match!")
else:
print("Not matched!")
OUTPUT:
RESULT:
Thus the Code to find the lower case letters are followed by underscore has executed successfully.
EXP NO- 3C DATE:
Step-1: Start.
Step-3: Assign a variable with value 0,add the values in list and store in the variable.
Step-5: Stop.
PROGRAM:
items=[11,12,13,15]
sum_numbers=0
x=sum(items)
sum_numbers += x
print(sum_numbers)
OUTPUT:
RESULT:
Thus the Code to find the sum of list has executed successfully.
EXP NO- 3D DATE:
Write a python function that get two tuples, slice the second tuple elements between the indices 1
and 3. Also add that sliced tuple to the first tuple.
AIM:
To Write a python function that get two tuples, slice the second tuple elements between the indices
1 and 3. Also add that sliced tuple to the first tuple.
ALGORITHM:
Step-1: Start.
Step-3: Store the indices of 1 and 3 in another variable and print it.
Step-5: Stop.
PROGRAM:
def tuples():
tuple1=eval(input())
tuple2=eval(input())
print(f"tuple1={tuple1}")
print(f"tuple2={tuple2}")
res=(tuple2[1],tuple2[2],tuple1[0],tuple1[1])
print(f"Resultant tuple={res}")
OUTPUT:
RESULT:
Thus the Code to find the new tuple list with indices 1 and 3 has executed successfully.
EX NO-4A DATE:
AIM:
To Write a program to merge the two python dictionaries into one.
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
dict2 = {'Thirty': 30, 'Forty': 40, 'Fifty': 50}
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
dict2 = {'Thirty': 30, 'Forty': 40, 'Fifty': 50}
dict1.update(dict2)
print(dict1)
OUTPUT:
RESULT:
EXP NO-4B
AIM:
ALGORTHAM:
Step-1: Start.
Step-4: Stop.
PROGRAM:
OUTPUT:
RESULT:
Write Python Program to find the perimeter of the circle using class name 'cse' and function name 'mech'.
AIM:
To Write Python Program to find the perimeter of the circle using class name 'cse' and function name 'mech'.
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
import math
class cse():
def mech(self,num):
a=2*3.14159*num
print(f"Perimeter of circle: {a:.2f}")
r=int(input())
obj=cse()
obj.mech(r)
OUTPUT:
RESULT:
Write Python Program to take the radius from the user and find the area of the circle using class
name 'pen' and function name 'stationary'.
AIM:
To Write Python Program to take the radius from the user and find the area of the circle using class
name 'pen' and function name 'stationary.
ALGORITHM:
Step-1: Start.
Step-2: Create a class using a function.
import math
class pen():
def stationary(self,num):
a=math.pi*num*num
print(f"Area of circle: {a:.2f}")
r=int(input())
obj=pen()
obj.statiory(r)
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step-1: Start.
Step-2: Create a class using a function.
PROGRAM:
class python():
def _init_(self,a):
self.a=a
def add(self):
print("This is parametrized constructor")
print(f"No. of members are {self.a}")
a=int(input())
obj=python(a)
obj.add()
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO- 5B DATE:
Create a Python class Vehicle that has a constructor (init) and destructor (del). We create an instance
from the class and delete it right after.
AIM:
To Create a Python class Vehicle that has a constructor (init) and destructor (del). We create an
instance from the class and delete it right after.
ALGORITHM:
Step-1: Start.
Step-5: Stop.
PROGRAM:
OUTPUT:
RESULT:
Write A Python Program to Calculated Add, Sub & Multiplication using Multiple Inheritance.
AIM:
To Write A Python Program to Calculated Add, Sub & Multiplication using Multiple Inheritance.
ALGORITHM:
Step-1: Start.
Step-2: Create three classes using a function.
Step-3: Use def function and a variable write the PROGRAM for addition,subtraction and multiplication .
Step-4: Print the statements.
Step-5: Stop.
PROGRAM:
class Calculation1:
def Summation(self,a,b):
return a+b;
class Calculation2:
def sub(self,a,b):
return a-b;
class Derived(Calculation1,Calculation2):
def multiply(self,a,b):
return a*b;
a=int(input())
b=int(input())
d = Derived()
print(d.Summation(a,b))
print(d.sub(a,b))
print(d.multiply(a,b))
OUTPUT:
RESULT:
Thus the program has been executed successfully.
DATE:
EXP NO-5D
Write a Python program to Get the name, age and location of a person and display using
Multilevel inheritance.
AIM:
To Write a Python program to Get the name, age and location of a person and display using
Multilevel inheritance.
ALGORITHM:
Step-1: Start.
Step-4: Stop.
PROGRAM:
class d():
def s():
print(f"{a} {b}
{c}")
a=input()
b=int(input())
c=input()
d.s()
OUTPUT:
RESULT:
AIM:
To Create two classes “Cat” and “Cow”. They’re different animals and make different sounds. So, the
make_sound() function should produce two different outputs based on the objects we pass through
them. In this case, we have created two objects “cat1” and “cow1”.
ALGORITHM:
Step-1: Start.
Step-2: Create two classes using a function.
Step-3: Use def function print the required statements.Call the function by using a variable.
Step-4: Stop.
PROGRAM:
class Cat:
def __init__(self, name, age):
self.name ,self.age = name,self.age = age
def make_sound(self):
print(f"Meow\nI am a cat. My name is {self.name}. I am {self.age} years old.")
class Cow:
def __init__(self, name, age):
self.name ,self.age = name,self.age = age
def make_sound(self):
print(f"Moo\nI am a cow. My name is {self.name}. I am {self.age} years old.")
cat1 = Cat("Kitty", 2.5)
cow1 = Cow("Fluffy", 4)
cat1.make_sound()
cow1.make_sound()
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-6B DATE:
write a python program to perform subtraction of two complex number using binary '+'
operator overloading
class name : complex
Ob1 = complex(1, 2)
Ob2 = complex(2, 3)
AIM:
To write a python program to perform subtraction of two complex number using binary '+'
operator overloading
class name : complex
Ob1 = complex(1, 2)
Ob2 = complex(2, 3)
ALGORITHM:
Step-1: Start.
Step-2: Create a class using a function.
Step-3: Use def function subtract the elements from first to second.Call the function
Step-4: Stop.
PROGRAM:
class saveetha:
def _init_(self,a,b):
self.a=a self.b=b
def _sub_(self,other):
return self.a-other.a ,self.b+other.b
obj1= saveetha(1, 2)
obj2= saveetha(2, 3)
obj3=obj1+obj2
print(obj3)
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-6C DATE:
Create the abstract method calculate_area which is of the abstract class 'Shape'. The implementation of
this abstract class can be defined in the sub-classes that inherit the class 'Shape'. 'Rectangle' and 'Circle'
are the two sub-classes that inherit the abstract class 'Shape'.
AIM:
To Create the abstract method calculate_area which is of the abstract class 'Shape'. The implementation
of this abstract class can be defined in the sub-classes that inherit the class 'Shape'. 'Rectangle' and
'Circle' are the two sub-classes that inherit the abstract class 'Shape'.
ALGORITHM:
Step-1: Start.
Step-2: Create three different classes using a function.
Step-3: Use def function pass the arguments.
Step-4: Stop.
PROGRAM:
from abc import ABC
class shape(ABC):
def test(self):
pass
class rectangle(shape):
length=5
b=3
def test(self):
return self.length*self.b
class circle(shape):
r=4
def test(self):
return 3.14*self.r*self.r
c=rectangle()
print("Area of a rectangle:",c.test())
d=circle()
print("Area of a circle:",d.test())
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-6D DATE:
Add the getter and setter method for the following class to change the values of variables name and
age which are private.Create an object of the class to invoke the methods.
AIM:
To add the getter and setter method for the following class to change the values of variables name
and age which are private.Create an object of the class to invoke the methods.
ALGORITHM:
Step-1: Start.
Step-2: Create a class using a function.
Step-3: Use def function print the same elements which is given by the user.
Step-4: Call the function by using a variable.
Step-5: Stop.
PROGRAM:
class Class1Students:
def __init__(self, name, age):
self.__name = name
self.__age = age
def speak(self):
print(f"my name is {self.__name}, and I am {self.__age} years old.")
Class1Students("Michael",40)
Class1Students("John",25)
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-7A DATE:
AIM:
To Write a Python program to find the result of a! - b! using recursion
ALGORITHM:
Step-1: Start.
Step-3: Get the inputs from the user and print the function.
Step-4: Stop.
PROGRAM:
def fact(n):
if n==0 :
return 1
else:
value= n*fact(n-1)
return value
n= int(input())
num=int(input())
print(fact(n)-fact(num))
OUTPUT:
RESULT:
Write a Python Program to implement the following function using nested function: fNo= 0 ;
if n=0
n; if n>4
f(4+f(2n)); if n<=4
AIM:
To Write a Python Program to implement the following function using nested function: fNo=
0 ; if n=0
n; if n>4
f(4+f(2n)); if n<=4
ALGORITHM
Step-1: Start.
Step-2: Using def function and if else statements write the PROGRAM.
Step-3: Get the inputs from the user and print the function.
Step-4: Stop.
PROGRAM:
def fun(a):
if a==0:
return 0
elif a>4:
return a
else:
return fun(4+fun(2*a))
a=int(input())
print(fun(a))
OUTPUT:
RESULT:
AIM:
To Write a python program to evaluate the series using recursion:
ALGORITHM
Step-1: Start.
Step-2: Using def function and if else statements write the PROGRAM.
Step-3: Get the inputs from the user and print the function.
Step-4: Stop.
PROGRAM
def fun(x,n):
if(n==0):
return 1
else:
return
((3**n)*(x**n)
+fun(x,n-1))
x=int(input())
n=int(input())
print(fun(x,n))
OUTPUT:
RESULT:
AIM:
ALGORITHM
Step-1: Start.
Step-2: Use two different def function and if statements write the PROGRAM.
Step-3: Get the inputs from the user and print the function.
Step-4: Stop.
PROGRAM:
def ispositive(num):
return ( (num>0))
def totalpositive(l, n):
if n == 1:
return ispositive(l[0])
return totalpositive(l, n - 1) + ispositive(l[n-1])
n=int(input())
l=[]
for i in range(n):
x=int(input())
l.appStop(x)
OUTPUT:
RESULT:
A 75m long train is running at 54 km/hr. Write a python program to find the time taken to cross
an electric pole? [Distance = speed*time]
Hint : Convert km/hr to m/sec by multiplying with (5/18)
AIM:
To write a program for A 75m long train is running at 54 km/hr. Write a python program to find
the time taken to cross an electric pole? [Distance = speed*time]
ALGORITHM
Step-1: Start.
Step-2: Get the distance and speed which is already given in the question.
Step-3: Use the speed and distance formula calculate the time.(time=(distance/speed)).
Step-4: Stop.
PROGRAM:
distance=75 speed=(54*(5/18))
time=(distance/speed)
print(time)
OUTPUT:
RESULT:
Write a python program to display elements from a list, present at odd index positions.
AIM:
To Write a python program to display elements from a list, present at odd index positions
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs from the user.Using for loop and appStop function store it in a list.
Step-3: Use another for loop and check whether the given number is even.If it is even print it by
using print statement.
Step-4: Stop.
PROGRAM:
arr=list()
a=int(input()) for
i in range(a):
arr.appStop(int(input()))
for i in range(a):
if (i%2!=0):
print(arr[i],Stop=' ')
OUTPUT:
RESULT:
Write a program that has a dictionary of names of students and their marks in five subjects. Create
another dictionary from this dictionary that has the name of the students and their total marks. Find out
the topper and the score.
AIM:
To Write a program that has a dictionary of names of students and their marks in five subjects. Create
another dictionary from this dictionary that has the name of the students and their total marks. Find out
the topper and the score.
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs from the user.
Step-3: Check the necessary conditions required and print the statements.
Step-4: Stop.
PROGRAM:
marks=eval(input()) total=0
total_marks=marks.copy()
for key,val in marks.items():
total=sum(val)
total_marks[key]=total
print(total_marks)
max=0
topper=''
for key,val in total_marks.items(): if
val>max:
max=val
topper=key
print("Topper is: ",topper, "with marks = ",max)
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-8D DATE:
Develop a python program to check the given UID valid or not according to the specified rules.
AIM:
To Develop a python program to check the given UID valid or not according to the specified rules.
ALGORITHM:
Step-1: Start.
Step-2: Using re module find the UID is valid or not.
Step-3: Use the lambda function and if else for the required
condition.
Step-4: Stop.
PROGRAM:
import re
for i in range(int(input())):
N = input().strip()
if N.isalnum() and len(N) == 10:
if bool(re.search(r'(.*[A-Z]){2,}',N)) and bool(re.search(r'(.*[0-9]){3,}',N)):
if re.search(r'.*(.).*\1+.*',N):
print('Invalid')
else:
print('Valid')
else:
print('Invalid')
else:
print('Invalid')
OUTPUT:
RESULT:
Write a python program to print the only the Diagonal elements of a matrix as shown below:
AIM:
To Write a python program to print the only the Diagonal elements of a matrix as shown below:
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs from the user.AppStop the items into the list. Step-3:
Give the required condition and print the diagonal elements.Step-4: Stop.
PROGRAM:
rows=int(input())
columns=int(input())
matrix=[[0]*columns for row in range(rows)]for i
in range(rows):
lines=list(map(int,input().split()))for
j in range(columns):
matrix[i][j]=lines[j]
print(matrix)
for i in range(rows):
for j in range(columns): if
(i==j):
print(matrix[i][j],Stop=" ") else:
print(" ",Stop=" ")
print()
OUTPUT:
RESULT:
Write a Python program to find the cube of all elements in a list using list comprehension
AIM:
To Write a Python program to find the cube of all elements in a list using list comprehension
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs from the user and then appStop it into a list.
Step-3: Print another list which are the cubes of the first list.
Step-4: Stop.
PROGRAM:
n=int(input())
L=[]
for i in range(n):
x=int(input())
L.appStop(x)
cube=[item**3 for item in L]
print(L)
print(cube)
OUTPUT:
RESULT:
Write a Python program to filter the numbers that are divisible by 7 and 5 in a list using filter ( )
AIM:
To Write a Python program to filter the numbers that are divisible by 7 and 5 in a list using filter ( )
ALGORITHM:
Step-1: Start.
Step-2: Use def function.Create a list and appStop the items into the list.
Step-3: Print the statements and check whether the number is divisible by 5 and 7.
Step-4: Stop.
PROGRAM:
def fun(x):
if x%5==0 and x%7==0:
return True
else:
return False
L=[]
a=int(input()) for
i in range(a):
x=int(input())
L.appStop(x)
s=list(filter(fun,L))
print(s)
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-9D DATE:
Write a Python PROGRAM to check whether the matrix is Magic square or not.
AIM:
To write a Python PROGRAM to check whether the matrix is Magic square or not.
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs from the user and store it in the form of a matrix.
Step-3: Print the given matrix first which is got from the user.
Step-4: Use the Magic square formula and print the whether it is magic square or not.
Step-5: Stop.
PROGRAM:
def create_matrix(n):
matrix = [[0]*n for row in
range(n)]
for i in range(n):
line= list(map(int,
input().split()))
for j in range(n):
matrix[i][j] = lines[j]
return matrix
def isMagicSquare( mat) :
n = len(mat)
sumd1=0
sumd2=0
for i in range(n):
sumd1+=mat[i][i]
sumd2+=mat[i][n-i-1]
if not(sumd1==sumd2):
return False
for i in range(n):
sumr=0
sumc=0
for j in range(n):
sumr+=mat[i][j]
sumc+=mat[j][i]
if not(sumr==sumc==sumd1):
return False
return True
n= int(input())
M=create_matrix(n)
if (isMagicSquare(M)) :
print( "Magic matrix")
else :
print( "Not a Magic matrix")
OUTPUT :
RESULT :
Write a python program to push only vowels into the stack from the given string
AIM:
To Write a python program to push only vowels into the stack from the given string.
ALGORITHM:
Step-1: Start.
Step-3: Get the inputs from the user and use for loop. Step-
Stop.
PROGRAM:
l=[]
s=input()
for i in s:
if i in ['a','e','i','o','u','A','E','I','O','U']:
l.appStop(i)
print("".join(l))
OUTPUT:
RESULT:
Write a python program to create a stack with a maximum size of 3 using Lifo Queue. Get the input
from the user and check whether the stack is full and then display the stack values in reverse order.
AIM:
To Write a python program to create a stack with a maximum size of 3 using Lifo Queue. Get the input
from the user and check whether the stack is full and then display the stack values in reverse order.
ALGORITHM:
Step-1: Start.
Step-2: After importing LIFOQueue from queue give the maximum size.
Step-3: Use for loop and check whether the stack is full at last print the stack.
Step-4: Stop.
PROGRAM:
from queue import LifoQueue
stack=LifoQueue(maxsize=3)
n=int(input())
for i in range(n):
stack.put(input())
print(stack.full())
for i in range(n):
print(stack.get())
OUTPUT:
RESULT:
Develop a python program to remove the two string values from the rear Stop.
AIM:
To Develop a python program to remove the two string values from the rear Stop.
ALGORITHM:
Step-1: Start.
Step-2: Get the inputs and use the for loop to appStop the items.
Step-3: Pop the first two elements and then print the list.
Step-4: Stop.
PROGARM:
q = []
n=int(input()) for
i in range(n):
q.appStop(input())
q.pop(0)
q.pop(0)
print(q)
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step-1: Start.
Step-2: Import ProrityQueue from queue.
Step-3: Use for loop to appStop the items.
Step-4: Stop.
PROGRAM:
from queue import PriorityQueue
que=PriorityQueue() n=int(input())
l=[]
for i in range(n):
l.appStop(int(input()))
for number in l:
que.put((-number, number))
while not que.empty():
print(que.get()[1])
OUTPUT:
RESULT:
Write a function to traverse the linked list and display it in the following format.
AIM:
To Write a function to traverse the linked list and display it in the following format.
ALGORITHM:
Step-1: Start.
Step-2: Create two classes for Slinked list and use def functions.
Step-3: Call the functions using a variable and then print.
Step-4: Stop.
PROGRAM:
class Node:
def _init_(self, data=None):
self.data = data
self.next = None
class SLinkedList:
def _init_(self):
self.head = None
def listprint(self):
printval = self.head
while printval is not None:
print (printval.data)
printval = printval.next
list = SLinkedList()
list.head = Node("Mon")
e2 = Node("Tue")
e3 = Node("Wed")7
list.head.next = e2
e2.next = e3
list.listprint()
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-11B DATE:
Write a python program to add new element at the start of the list.
AIM:
To Write a python program to add new element at the start of the list.
ALGORITHM:
Step-1: Start.
Step-2: Create two classes for Linked list and use def functions.
Step-3: Call the functions using a variable and then print.
Step-4: Stop.
PROGRAM:
class Node:
def _init_(self, data):
self.data = data
self.next = None
class LinkedList:
def _init_(self):
self.head = None
def push_front(self, newElement):
newNode = Node(newElement)
newNode.next = self.head self.head
= newNode
def PrintList(self):
temp = self.head
if(temp != None):
print("The list contains:", Stop=" ")
while (temp != None):
print(temp.data, Stop=" ")
temp = temp.next
print()
else:
print("The list is empty.")
MyList = LinkedList()
MyList.push_front(10)
MyList.push_front(20)
MyList.push_front(30)
MyList.PrintList()
OUTPUT:
RESULT:
Thus the program has been executed successfully.
EXP NO-11C DATE:
AIM:
ALGORITHM:
Step-1: Start.
Step-2: Create two classes for Slinked list and use def functions.
Step-3: Call the functions using a variable and then print.
Step-4: Stop.
PROGRAM:
class Node:
def _init_(self, data):
self.item = data
self.nref = None
self.pref = None
class DoublyLinkedList:
def _init_(self):
self.start_node = None
def insert_in_emptylist(self, data): if
self.start_node is None:
new_node = Node(data) self.start_node =
new_node
else:
print("list is not empty")
OUTPUT:
RESULT:
Type a python function to insert elements at the beginning of the doubly linked list.
AIM:
To Type a python function to insert elements at the beginning of the doubly linked list.
ALGORITHM:
Step-1: Start.
Step-2: Create two classes for DoublyLinked list and use def functions.
Step-4: Stop.
PROGRAM:
class Node:
def _init_(self, data):
self.item = data
self.nref = None
self.pref = None
class DoublyLinkedList:
def _init_(self):
self.start_node = None
def traverse_list(self):
if self.start_node is None:
print("List has no element")
return
else:
n = self.start_node
while n is not None:
print(n.item , "
") n = n.nref
new_linked_list = DoublyLinkedList()
new_linked_list.insert_in_emptylist(40)
new_linked_list.insert_at_start(30)
new_linked_list.insert_at_start(20)
new_linked_list.insert_at_start(10)
new_linked_list.traverse_list()
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step-1: Start.
Step-2: Create an empty list and appStop the items into the list.
Step-4: Stop.
PROGRAM:
stack = []
stack.appStop('a')
stack.appStop('b')
stack.appStop('c')
print("Stack after elements are pushed:")
print(“stack”)
OUTPUT:
RESULT:
Type a python PROGRAM to insert 3 elements. Also check and print the index value of the elements
stored in the stack.
AIM:
To Type a python PROGRAM to insert 3 elements. Also check and print the index value of the elements
stored in the stack.
ALGORITHM:
Step-1: Start.
Step-2: Create an empty list and appStop the items into the list.
Step-4: Stop.
PROGRAM:
stack = []
stack.appStop('a')
stack.appStop('b')
stack.appStop('c')
print('Initial stack: ' + str(stack))for i
in range(len(stack)):
print(i, Stop=" ")
print(stack[i]
OUTPUT:
RESULT:
List out the candidates appeared for the interview and display the slot (or) position of third candidate.
AIM:
To List out the candidates appeared for the interview and display the slot (or) position of third candidate.
ALGORITHM:
Step-1: Start.
Step-2: Create an empty list and appStop the items into the list.
Step-3: Print the list and then print the index number for the second element.
Step-4: Stop.
PROGRAM:
interview = []
interview.appStop("Suresh")
interview.appStop("Padma")
interview.appStop("Xavier")
print('List of candidates appeared for the interview:')
print(interview)
print('Display the slot number allotted for "Candidate_2": ')
print(interview.index("Xavier"))
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step-1: Start.
Step-2: Create an empty list and appStop the items into the list.
Step-4: Stop.
PROGRAM:
queue = []
queue.appStop('a')
queue.appStop('b')
queue.appStop('c')
queue.appStop('d')
print('Initial Queue: ' + str(queue))front
= queue[0]
print("\nElement at the front of the queue is ............", front)
rear = queue[3]
print("\nElement at the rear of the queue is ............. ", rear)
OUTPUT:
RESULT: