[go: up one dir, main page]

0% found this document useful (0 votes)
15 views56 pages

Shakthi Py-record 12

Uploaded by

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

Shakthi Py-record 12

Uploaded by

ShAkThi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 56

INDEX

S.NO DATE TOPIC PA MARK T.SIGN


GE
NO.
1 12-12-2022 Write a python program to Add two complex numbers. 1

2 13-12-2022 Write a python program to read one string and integer 2


and print the values
3 14-12-2022 Write a python program to find rate of interest based 3
on the user given principle, time & SI.

4 14-12-2022 Write a python program to read one string and integer 4


and print the values.

5 13-01-2023 Python Program to print numbers range 5


from M to N (including M and N values)

Write a Python program to print the even numbers from a


6 17-01-2023 given list 6

7 18-01-2023 Write a python program to print the quotient and 7


remainder of the division on the given numbers using
built in fun divmod()

8 17-01-2023 Create a Python program to print the simple star pattern 8


using a for loop.

9 20-01-2023 Write a python program to compute the length of the given 9


string .

10 20-01-2023 Write a Python program to find sequences of lowercase 10


letters joined with a underscore.

11 20-01-2023 Write a Python program to sum all the items in a list. 11


[11,12,13,15].

12 21-01-2023 Write a python function that get two tuples,print indices1 12


and3.Add that sliced tuple to the first tuple.

13 23-01-2023 Write a program to merge the two python dictionaries into 13


one
14 24-01-2023 Place msg="You're out of list range" to avoid 14
IndexError.
15 24-01-2023 Write Program to find the perimeter of circle 15
using class name 'cse' and function as ‘mech’
S.NO DATE TOPIC PAG MA T.SIGN
E RK
NO.
16 24-01-2023 Write Python Program to take the radius from 16
the user and find the area of the circle using class
name 'pen' and function name 'stationary'.

17 03-02-2023 Write a python PROGRAM to implement a parameterised 17


constructor with the no of family members as arguments and
print the message with the count.
18 03-02-2023 Create a Python class Vehicle that has a constructor 18
(init) and destructor (del). We create an instance fromthe
class and delete it right after.
19 04-02-2023 Write A Python Program to Calculated Add, Sub & 19
Multiplication using Multiple Inheritance.
20 04-02-2023 Write a Python program to Get the name, age 20
and location of a person and display using
Multilevel inheritance.

21 21-02-2023 Create two classes “Cat” and “Cow”. They’re different 21


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”.
22 08-09-2023 write a python program to perform subtraction of two 22
complex number using binary '+' operator overloading
23 08-09-2023 Create the abstract method calculate_area which is of the 23
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'.

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

25 22-03-2023 Write a Python program to find the result of a! - b! 25


using recursion
26 24-03-2023 Write a Python Program to implement the following 26
function using nested function
S.NO DATE TOPIC PAG MA T.SIGN
E RK
NO
27 01-04-2023 Write a python program to evaluate the series using 27
recursion:

by collecting the x,n and a values from the user.


28 01-04-2023 Write a program to count the positive numbers using 28
recursion
29 03-04-2023 A 75m long train is running at 54 km/hr. Write a 29
python program to find the time taken to cross anelectric
pole?
30 04-04-2023 Write a python program to display elements from alist, 30
present at odd index positions.
31 04-04-2023 Write a program that has a dictionary of names of students 31
and their marks in five subjects. Create another dictionary
from this dictionary that has the name of the students and
their total marks. Find outthe topper and the score.

32 03-04-2023 Develop a python program to check the given UID valid or not 32
according to the specified rules.

33 10-04-2023 Write a python program to print the only the Diagonal 33


elements of a matrix as shown below:
34 10-04-2023 Write a Python program to find the square of all elements in a 34
list using list comprehension
35 12-04-2023 Write a Python program to filter the numbers that are 35
divisible by 7 and 5 in a list using filter ( )
Write a Python PROGRAM to check whether the matrix is
36 19-04-2023 Magic 36
square or not.
37 17-05-2023 Write a python program to push only vowels into the 38
stack from the given string
38 17-05-2023 Write a python program to create a stack with a maximum 39
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.
S.NO DATE TOPIC PAG MA T.SIGN
E RK
NO
39 22-05-2023 Develop a python program to remove the two string values 40
from the rear Stop.
40 22-05-2023 Develop a python program to Reverse values in Queue 41

41 23-05-2023 Write a function to traverse the linked list and display it in 42


the following format.
42 24-05-2023 Write a python program to add new element at the 43
start of the list.
43 24-05-2023 Write a python program to traverse the elements in 44
doubly linked list.
44 31-05-2023 Type a python function to insert elements at the 46
beginning of the doubly linked list.
45 01-06-2023 Type and display the elements pushed in stack. 48

Type a python PROGRAM to insert 3 elements. Also check


46 01-06-2023 and print 49
the index value of the elements stored in thestack.

47 02-06-2023 List out the candidates appeared for the interview anddisplay 50
the slot (or) position of third candidate.

Type a python PROGRAM to add 4 elements in a


48 02-06-2023 queue.Print the 51
element present in the front and rear of queue.
EX NO- 1A DATE:

Write a python program to Add two complex numbers.


AIM:

To write a python program to Add two complex numbers. c1=4+2j


c2=5+3j
.
ALGORITHM:

Step-1: Start.

Step-2: Get the inputs as c1,c2 which is already given in question.

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-2: Prompt the user to input a value and store it in variable a.

Step-3: Prompt the user to input another value and store it in variable b.

Step-4: Print the values of a and b using the print statement.

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-2: Prompt the user to enter the temperature.

Step-3: Check if the temperature is greater than 97.

Step-4: If the condition is true, print "The person has fever".

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-2: Get the integer inputs from the user.

Step-3: Using for loop give range values.

Step-4: print the numbers.

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-2: Initialize an empty list called enum.

Step-3: Using a define function create a function called “enum”.

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-2: Get the integer inputs from the user.

Step-3: Use the built in function “divmod()”.

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-2: Get the rows input from the user.

Step-3: Give the range of i by using for loop.

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:

Write a python program to compute the length of the given string .


AIM:

To write a python program to compute the length of the given string.

ALGORITHM:

Step-1: Start.

Step-2: Get the string input from the user.

Step-3: Using built in function find the length of string.

Step-4: Store it in a variable and print it.

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-2: Get the string input from the user.

Step-3: Using the search function check whether there is an underscore.

Step-4: If found print”Found a match!” else print “Not matched!”.

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:

Write a Python program to sum all the items in a list [11,12,13,15].


AIM:

To Write a Python program to sum all the items in a list [11,12,13,15].


ALGORITHM:

Step-1: Start.

Step-2: Copy the list which is given in the question.

Step-3: Assign a variable with value 0,add the values in list and store in the variable.

Step-4: Print 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-2: Get the tuple input from the user.

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:

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}

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-2: Store the given in variables.

Step-3: Using builtin function called “update” join two dictionaries.

Step-4: print the statements.

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:

Thus the program has been executed successfully.


DATE:

EXP NO-4B

Place msg="You're out of list range" to avoid IndexError.

AIM:

To Place msg="You're out of list range" to avoid IndexError.

ALGORTHAM:

Step-1: Start.

Step-2: Create a list with a variable.

Step-3: Using try and except print the statements.

Step-4: Stop.

PROGRAM:

lst=[5, 10, 20]


msg="You're out of list range"
try:
print(lst[5])
except:
print(msg)

OUTPUT:

RESULT:

Thus the program has been executed successfully.


DATE:
EXP NO-4C

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-2: Create a class using a function.

Step-3: Use def function in it write the formula of perimeter of circle.

Step-4: And then print it.Call the function by using a variable.

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:

Thus the program has been executed successfully.


EXP NO-4D DATE:

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.

Step-3: Use def function in it write the formula of area of circle.

Step-4: And then print it.Call the function by using a variable.


Step-5: Stop.
PROGRAM:

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:

Thus the program has been executed successfully.


EXP NO-5A DATE:

Write a python PROGRAM to implement a parameterised constructor with the no of family


membersas arguments and print the message with the count.

AIM:

To Write a python PROGRAM to implement a parameterised constructor with the no of family


membersas arguments and print the message with the count.

ALGORITHM:
Step-1: Start.
Step-2: Create a class using a function.

Step-3: Use def function print the statements.

Step-4: Call the function by using a variable.


Step-5: Stop.

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-2: Create a class using a function.

Step-3: Use def function print the statements.

Step-4: Call the function by using a variable.

Step-5: Stop.

PROGRAM:

class python(): def


_init_(self):
print("Vehicle created.")
def _del_(self):
print("Destructor called, vehicle deleted.") obj=python()
del obj

OUTPUT:

RESULT:

Thus the program has been executed successfully.


DATE:
EXP NO-5C

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-2: Create a class using a function.

Step-3: Use def function print the given inputs .

Step-4: Stop.

PROGRAM:

class d():
def s():
print(f"{a} {b}
{c}")
a=input()
b=int(input())
c=input()
d.s()

OUTPUT:

RESULT:

Thus the program has been executed successfully.


DATE:
EXP NO-6A
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”.

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:

Write a Python program to find the result of a! - b! using recursion

AIM:
To Write a Python program to find the result of a! - b! using recursion

ALGORITHM:

Step-1: Start.

Step-2: Using 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 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:

Thus the program has been executed successfully.


EXP NO-7B DATE:

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:

Thus the program has been executed successfully.


EXP NO-7C DATE:

Write a python program to evaluate the series using recursion:

by collecting the x,n and a values from the user.

AIM:
To Write a python program to evaluate the series using recursion:

by collecting the x,n and a values from the user.

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:

Thus the program has been executed successfully.


EXP NO-7D DATE:

Write a program to count the positive numbers using recursion.

AIM:

To Write a program to count the positive numbers using recursion

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:

Thus the program has been executed successfully.


EXP NO-8A DATE:

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]

Hint : Convert km/hr to m/sec by multiplying with (5/18)

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:

Thus the program has been executed successfully.


EXP NO-8B DATE:

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:

Thus the program has been executed successfully.


EXP NO-8C DATE:

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:

Thus the program has been executed successfully.


EXP NO-9A DATE:

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:

Thus the program has been executed successfully.


EXP NO-9B DATE:

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:

Thus the program has been executed successfully.


EXP NO 9C DATE:

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 :

Thus the program has been executed successfully.


EXP NO-10A DATE:

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-2: Create an empty list.

Step-3: Get the inputs from the user and use for loop. Step-

4: AppStop letters if it is an vowel and then print it.Step-5:

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:

Thus the program has been executed successfully.


EXP NO-10B DATE:

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:

Thus the program has been executed successfully.


EXP NO:10C DATE:

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:

Thus the program has been executed successfully.


EXP NO-10D DATE:

Develop a python program to Reverse values in Queue.

AIM:

To Develop a python program to Reverse values in Queue.

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:

Thus the program has been executed successfully.


EXP NO:11A DATE:

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:

Write a python program to traverse the elements in doubly linked list.

AIM:

To Write a python program to traverse the elements in doubly linked list.

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")

def insert_at_start(self, data):if


self.start_node is None:
new_node = Node(data) self.start_node =
new_nodeprint("node inserted")
return
new_node = Node(data) new_node.nref
= self.start_nodeself.start_node.pref =
new_nodeself.start_node = new_node
def insert_at_Stop(self, data):if
self.start_node is None:
new_node = Node(data)
self.start_node = new_nodereturn
n = self.start_node while
n.nref is not None:
n = n.nref
new_node = Node(data)
n.nref = new_node
new_node.pref =
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(50)
new_linked_list.insert_at_start(10)
new_linked_list.insert_at_start(5)
new_linked_list.insert_at_start(18)
new_linked_list.insert_at_Stop(29)
new_linked_list.insert_at_Stop(39)
new_linked_list.insert_at_Stop(49)
new_linked_list.traverse_list()

OUTPUT:

RESULT:

Thus the program has been executed successfully.


EXP NO-11D DATE:

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-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")

def insert_at_start(self, data):if


self.start_node is None:
new_node = Node(data) self.start_node =
new_nodeprint("node inserted")
return
new_node = Node(data) new_node.nref
= self.start_nodeself.start_node.pref =
new_nodeself.start_node = new_node

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:

Thus the program has been executed successfully.


DATE:
EXP NO-12A

Type and display the elements pushed in stack.

AIM:

To Type and display the elements pushed in stack.

ALGORITHM:

Step-1: Start.

Step-2: Create an empty list and appStop the items into the list.

Step-3: Print 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:

Thus the program has been executed successfully.


DATE:
EXP NO-12B

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-3: Print the list with the index.

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:

Thus the program has been executed successfully.


EXP NO-12C DATE:

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:

Thus the program has been executed successfully.


EXP NO-12D DATE:

Type a python PROGRAM to add 4 elements in a queue.


Print the element present in the front and rear of queue.

AIM:

To Type a python PROGRAM to add 4 elements in a queue.


Print the element present in the front and rear of queue.

ALGORITHM:
Step-1: Start.

Step-2: Create an empty list and appStop the items into the list.

Step-3: Print 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:

Thus the program has been executed successfully.

You might also like