0% found this document useful (0 votes)
37 views69 pages

PYTHON 1 Merged

Uploaded by

Nanda Kishore
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)
37 views69 pages

PYTHON 1 Merged

Uploaded by

Nanda Kishore
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
You are on page 1/ 69

PYTHON RECORD

S.NO DATE EXPT. PG.NO MARKS SIGN


NAME
Write a python program to print
1. the following integer literals
123,456,789

Write a python program to Add


2. two complex numbers. Get the
inputs using eval ().

Correct the python program to


3. print 'S' and 'k' using character
literal.

Write a python program for the


4. following problem statement.

Construct a Python Program to


5. find Factorial of the number '5'
AIM: To construct a Python
Program to find Factorial of the
number '5'

A python program to define a


6. function that accepts the side of a
square and returns the area of a
square.

Write a lambda function which


7. takes z as a parameter and
returns z*11 using python

Python program to print alternate


8. number pattern. Get the number
of rows as input.

Write a python function that


9. accepts a string and converts it
into upper case, lower case and
title case.
Write a Python program to
10. check that a string contains only
a certain set of characters (in
this case a-z, A-Z and 0-9).

Write a Python program to count the


11. number of strings where the string
length is 2 or more and the first and
last character are same from a given
list of strings.

Write a python program to create


12. the tuple by the multiples of 5 up
to N. Get the N value from the
user.

Write a Python script to check


13. whether a given key 5,9 already
exists in a dictionary.

Place result="You can't divide with


14. 0" to the right place so that program
avoids ZeroDivisionError.

Write a python program to Place


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

16. Write Python Program to take


the radius from the user and find
the area of the circle using class
name 'cse' and function name
'mech'

Write a python code to create a


17. student class with default
constructor and a user defined
function to display the text
"welcome" with student name given
to the function.
Create a Python Class Student
18. with a destructor.

Write a Python Program to Display


19. the Employee Details
EmpId , Emp Name.,
Write a Python program to Get the
20. name, age and salary of a person and
display using Multilevel inheritance.

Create a parent class vehicle with


21. the following methods
show(),max_speed,change_gear()
inherit the car class from the vehicle
class,where the car class methods
max_speed(),change_gear()
override the same methods of base
class using method overriding

Create two classes Employee and Admin.


22. These two different classes have the same
method name info(). This method contains
information(name, department) about
employee in Employee class and admin in
Admin class.after initializing classes, Create
two objects for respective classes. Then the
method info() is called. Once by the object
of Employee class and once by the object of
Admin class.
Create two classes “Cat”
23. 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”.

Create a Class Student with


24. the private members name
and age, Add getter and setter
to initialize the age variable.

Write a Python program to


25. find the sum of first n
Natural Numbers
Write a Python program
26. to print the sum of digits
of a positive number
using tail recursion

write a python program to


27. perform product of two
complex number using
binary '+' operator
overloading

Create a Class Student


28. with the private
members name and age
,Add getter and setter to
initialize the age variable.

Write a program to be
29. provided code stub reads
two strings
Write a python program to
30. display elements from a
list, present at odd index
positions.
Write a program to be
31. provided code stub reads
and integer,n , from STDIN.
For all non- negative
integers i > n, print i
Develop a python program
32. to count the number of
vowels and consonants
from the given string
Write a python program to
33. print the matrix of given
inputs

Write a Python class


34. program to generate all
even numbers between 200
and 300 and store in a list
using list comprehension

Find the transpose of a


35. matrix using list
Comprehension.
Write a Python class to
36. perform Insertion sort

Write a python program to


37. push only vowels into the
stack from the given string

Write a python program to


38. check whether the given
string is palindrome

Write a python program to


39. add only the even unique
numbers using appendleft()
from n given number
Write a python program to
40. get the 4 integer values
from user and display the
values using
multiprocessing library
Write a function to traverse
41. the linked list and display it
in the following

Write a function to traverse


42. the linked list and display it
in the following format
Write a python function to
43. search an element in the
doubly linked list.

Write a python function to


44. insert elements at the
beginning of the doubly
linked list.
Write a python program
45. and display the elements
pushed in stack

Type a python code to


46. insert 3 elements. Also
check and print the index
value of the elements
stored in the stack.
Type a python code and
47. display all the elements
inserted and also display
after deleting the first
Type a python code to
48. insert 3 players in the list.
Also check and print the
index value of the
MODULE-1
EX:1.1
Write a python program to print the following integer literals
123,456,789
AIM:
To write a python program print the following integer literals
ALGORITHM:
1. DECLARE VARIABLES FOR THE FOLLOWING INTEGER LITERALS
2. PRINT THOSE VARIABLES
PROGRAM:
a=123
b=456
c=789
print(a,b,c)
OUTPUT:

RESULT:
Thus, the output has been successfully executed!
MODULE-1
EX: 1.2

Write a python program to Add two complex numbers. Get


the inputs using eval ().
Aim:
To Write a python program to Add two complex numbers. Get
the inputs using eval ().
Algorithm:
1. Get the input.
2. Add the input values.
3. Print the result.

Program:
a=int(input())
b=int(input())
print(a+b)
print(a-b)
print(a*b)

Ouput:
Module-1
Ex: 1.3
Correct the python program to print 'S' and 'k' using character
literal.
Aim:
To correct the python program to print 'S' and 'k' using character
literal.
Algorithm:
1. Declare ‘S’ and ‘k’ in different variables.
2. Print those
variables. Program:
v = "S"
w = "k"
print(v)
print(w)
Output:
Module –1
EX:1.4
Write a python program for the following problem statement.
Aim:
To write a python program for the following problem statement.
Algorithm:
1.Read two integers from STDIN and print three lines where:
2.The first line contains the sum of the two numbers.
3. The second line contains the difference of the two numbers (first - second).
4. The third line contains the product of the two
numbers. 5.Print the result.
Program:
a=int (input ())
b=int (input ())
c=a+b
d=a-b
e=a*b
print(c)
print(d)
print(e)
OUTPUT:

RESULT:
Thus, the output has been successfully executed!
Module –2
Ex:2.1
Construct a Python Program to find Factorial of the number '5' AIM: To construct
a Python Program to find Factorial of the number '5'
ALGORITHM:
Step1:Get two input from the user
Step2: if the input is equal to a%2==0 print EVEN
Step3: else print ODD
Step4: Execute the program.
PROGRAM:
fact=1
n=int(input())
for i in range (1,n+1):
fact=fact*i
print("Factorial of the given number",n,"is", fact)
OUTPUT:

RESULT:

Thus, the program has been successfully executed.


MODULE-2
Ex:2.2
A python program to define a function that accepts the side of a square and returns the area
of a square.
AIM:
write a python program to define a function that accepts the side of a square and returns
the area of a square.
ALGORITHM:
Step1:Get two input from the user
Step2:put def function
Step3:area=side*side and return it
Step4:Execute the program.
PROGRAM:
def area(side):
area=side*side
return area
side=int(input())
print(area(side))
OUTPUT:

RESULT:
Thus,the program has been successfully executed!
Module-2
EX:2.3
Write a lambda function which takes z as a parameter and returns z*11 using python.
AIM:
To write a lambda function which takes z as a parameter and returns z*11 using python.
ALGORITHM:
1. Declare a parameter as z.
2. Use lambda function by product of 11.
3. Print the
result. PROGRAM:
z=int(input())
mul=lambda z:z*11
print(mul(z))
OUTPUT:

RESULT:
Thus ,the output has been successfully executed!
Module –2
Ex:2.4
Python program to print alternate number pattern. Get the number of rows as input.
AIM:
To print alternate number pattern. Get the number of rows as input.
ALGORITHM:
1. Get the number of rows as input.
2. Analyze the no. of rows and columns to be executed!
3. Print the
result. Program:
n=int(input())
k=1
for i in range(1,n+1):
for j in range(1,i+1):
print(k,end=" ")
k+=2
print()
Output:

Result:
Thus, the output has been successfully executed!
Module –3
Ex: 3.1
Write a python function that accepts a string and converts it into upper case, lower case and title case.

AIM:

To write a python function that accepts a string and converts it into upper case, lower case and title case.

ALGORITHM:

1. Get the input from the user.


2. Change the cases using lower cases and upper cases.
3. Print the result.

TEST:

modify("Hard work matters") Hard work matters


HARD WORK MATTERS
hard work matters
Hard Work Matters

PROGRAM:

def modify(a):

b=a.upper()

c=a.lower()

d=a.title()

print(a)

print(b)

print(c)

print(d)

a="Hard work matters"

OUTPUT:

RESULT:
Thus,the output has been successfully executed.

MODULE –3
EX: 3(B)
Write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-Z
and 0-9).
AIM:
To write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-
Z and 0-9).
ALGORITHM:

1. Get the input from the user.


2. Using regex, Check the following set of characters.
3. If it exists, print yes
4. Else print No
PROGRAM:
import re
def str_(text):
if re.search("[^a-zA-Z0-9.]", text):
print("False")
else:
print("True")
text=input()
str_(text)
OUTPUT:

RESULT:
Thus, the output has been successfully executed.
Module –3
EX.NO: 3C
Write a Python program to count the number of strings where the string length is 2 or more and the first and last
character are same from a given list of strings.

Sample List : match_words=['abd', '1221', 'abx', '1221']


Expected Result : 2

AIM:
To count the number of strings where the string length is 2 or more and the first and last character are same from a
given list of strings.

ALGORITHM:
1. Creating list for the following strings.

2. Count the string.

3. Print the length of string.

PROGRAM:
list1=['abd', '1221', 'abx',
'1221'] count=0
for i in list1:
if len(i) >= 2 and i[0]==i[-1]:
count += 1
print(count)
Output:

Result:
Thus, the output has been verified suucessfully.
Module –3
Ex: 3(D)

Write a python program to create the tuple by the multiples of 5 up to N. Get the N value
from the user.
AIM:
To write a python program and create the tuple by the multiple of 5 upto N and get the N
value from the user.
ALGORITHM:
1. Start the program.
2. Create a tuple by the multiple of 5 upto N.
3. Print the
result. PROGRAM:
a=int(input())
b=[]
for i in range(1,a):
if i%5==0:
b.append(i)
print(tuple(b))
OUTPUT:

RESULT:
Thus, the output has been successfully executed.
Module –4
Ex: 4(A)
Write a Python script to check whether a given key 5,9 already exists in a dictionary.

d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6:


60} AIM:
To write a Python script to check whether a given key 5,9 already exists in a dictionary.
ALGORITHM:
1. Start the program.
2. Create a given dictionary.
3. Checking the key 5,9 exist in the dictionary.
4. Print the result.
PROGRAM:
d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
n=5
n1=9
if n in d.keys():
print("Key is present in the dictionary")
else:
print("Key is not present in the dictionary")
if n1 in d.keys():
print("Key is present in the dictionary")
else:
print("Key is not present in the dictionary")
OUTPUT:

RESULT:
Thus , the output has been successfully executed.

MODULE-4
EX: 4(B)
Place result="You can't divide with 0" to the right place so that program avoids
ZeroDivisionError.
AIM:
To place the result ="You can't divide with 0" to the right place so that program avoids
ZeroDivisionError.
ALGORITHM:
1. Start the program.
2. Get the input from the user.
3. Use try method in such a way that it avoids ZeroDivisionError.
4. Use except method to print if ZeroDivisionError occurs.
5. Print the
result. PROGRAM:
a=int(input())
b=int(input())
try:
result=a/b
print(result)
except ZeroDivisionError:
print("You can't divide with 0")
OUTPUT:

RESULT:
Thus , the output has been successfully executed.

Module –4
Ex No. : 4(C)
Write a python program to Place msg="You're out of list range" to avoid IndexError

AIM:
Place msg="You're out of list range" to avoid IndexError
ALGORITHM:
Step1: put a list
Step2: try print(list(5))
Step3:except print that you are out of range
Step4:Execute the program.
PROGRAM:
lst=[5, 10, 20]
try:
print(lst[5])
except:
print("You're out of list range”)
OUTPUT:

RESULT:
Thus, the program has been successfully executed.
MODULE-4
EX.NO: 4(D)

Write Python Program to take the radius from the user and find the area of the circle using
class name 'cse' and function name 'mech'
AIM:
To write Python Program to take the radius from the user and find the area of the circle
using class name 'cse' and function name 'mech'.
ALGORITHM:
1. Start the program.
2. Create classes named as “cse” and “mech”
3. Give inputs from the user.
4. Print the
result. Program:
class cse:
radius=int(input())
area=3.1416*radius*radius
def mech():
cse.area
area=cse()
print("Area of circle:",cse.area)
area.mech
OUTPUT:
RESULT:
Thus, the output has been successfully executed.
Module-5
EX. NO:5(A)
Write a python code to create a student class with default constructor and a user defined function to
display the text "welcome" with student name given to the function.
AIM:

To write a python code to create a student class with default constructor and a user defined function to
display the text "welcome" with student name given to the function.
ALGORITHM:
1. Start the program.
2. Create a class named “Student”
3. Display the text “welcome”
4. Print the result.
PROGRAM:
class Student:
def init (self,name):
self.name=name
def display(self):
print("This is non parametrized constructor")
print("Hello",self.name)
name=input()
s=Student(name)
s.display()
OUTPUT:
RESULT:
Thus, the output has been successfully executed.
MODULE-5
EX. NO: 5(B)
Create a Python Class Student with a destructor.
AIM:
To Create a Python Class Student with a destructor.
ALGORITHM:
1. Start the program.
2. Create a constructor.
3. Create a destructor.
4. Stop the program.
PROGRAM:
class Student:
def init (self):
print("Inside Constructor")
print("Object initialized")
def name(self):
print("Hello, my name is Emma")
def del (self):
print("Inside destructor")
print("Object destroyed")
obj=Student()
obj.name()
del obj
OUTPUT:
RESULT:
Thus, the output has been successfully
executed. MODULE –5
EX. NO:5(C)
Write a Python Program to Display the Employee Details
EmpId , Emp Name.,

AIM:

To write a Python Program to Display the Employee Details


EmpId , Emp Name.,

PROGRAM:
class Det:
def init (self,name,id):
self.name=name
self.id=id
class Display(Det):
def view(self):
print((self.id,self.name))
name="Employee1"
id=198754
d=Display(name,id)
d.view()
OUTPUT:

RESULT:
Thus , the output has been successfully executed.
MODULE-5

EX. NO:5(D)

Write a Python program to Get the name, age and salary of a person and display using Multilevel inheritance.

AIM:

To write a Python program to Get the name, age and salary of a person and display using Multilevel inheritance.

ALGORITHM:

1. Start the program.


2. Create a class to display the functions of the following details of a person with respect to Multilevel inheritance.
3. Print the result
4. End the program

PROGRAM:

class Person:

def init (self,personname):

self.personname=personname

class Age(Person):

def init (self,personname,age):

self.age=age

Person. init (self,personname)

class Salary(Age):

def init (self,personname,age,salary):

self.salary=salary

Age. init (self,personname,age)

def print_name(self):

print(self.personname,self.age,self.salary)

personname="srinivas"

age=24

salary=23456

obj=Salary(personname,age,salary)

obj.print_name()

OUTPUT:
RESULT:

Thus, the output has been successfully executed.

MODULE-6
EX. NO:6(A)
Create a parent class vehicle with the following methods show(),max_speed,change_gear()
inherit the car class from the vehicle class,where the car class methods
max_speed(),change_gear() override the same methods of base class using method
overriding
AIM:
To create a parent class inherit the car class from vehicle class with the following methods.
ALGORITHM:
1. Start the program

2. Create a parent class that inherit from vehicle class with the following

methods 3.Print the result


4. End the program
PROGRAM:
class Vehicle:
def init (self, name, color,
price): self.name = name
self.color = color
self.price = price
def show(self):
print('Details:', self.name, self.color, self.price)
def max_speed(self):
print('Vehicle max speed is 150')
def change_gear(self):
print('Vehicle change 6 gear')
# inherit from vehicle class
class Car(Vehicle):
def max_speed(self):
print('Car max speed is
240')
def change_gear(self):
print('Car change 7 gear')
# Car Object
car = Car('Car x1', 'Red',
20000) car.show()
car.max_speed()
car.change_gear()
vehicle = Vehicle('Truck x1', 'white', 75000)
vehicle.show()
vehicle.max_speed()
vehicle.change_gear()
# calls method from a Vehicle class
OUTPUT:

RESULT:
Thus the output has been succesfully executed.
MODULE –6
EX NO: 6(B)
Create two classes Employee and Admin. These two different classes have the same method name info(). This method contains
information(name, department) about employee in Employee class and admin in Admin class.after initializing classes, Create two objects for
respective classes. Then the method info() is called. Once by the object of Employee class and once by the object of Admin class.
AIM:
To Create two classes Employee and Admin. These two different classes have the same method name info(). This method contains
information(name, department) about employee in Employee class and admin in Admin class.after initializing classes, Create two objects for
respective classes.
ALGORITHM:

1. Start the program.


2. Creating a classess Employee and Admin with following methods
3. Print the result
4. Stop the
program PROGRAM:
class Employee:
def init (self,name,dept):
self.name=name
self.dept=dept
def info(self):
print(f"{self.name} from {self.dept}")
#Add your code Here
class Admin:
def init (self,name,dept):
self.name=name
self.dept=dept
def info(self):
print(f"{self.name} from {self.dept}")
obj_emp = Employee("Rooney","Electronics")
obj_emp.info()
obj_adm = Admin("Kalesh","CS")
obj_adm.info()
OUTPUT:
RESULT:

Thus the output has been successfully executed.

MODULE-6
EX.NO:6(C)
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:
1. Start the program
2. Creating classes CAT and COW with make_sound() function
3. Print the result
4. Stop the program
PROGRAM:
class Cat:
def init (self, name,
age): self.name = name
self.age = age
def info(self):
print(f"I am a cat. My name is {self.name}. I am {self.age} years old.")
def make_sound(self):
print("Meow")
class Cow:
def init (self, name,
age): self.name = name
self.age = age
def info(self):
print(f"I am a Cow. My name is {self.name}. I am {self.age} years old.")
def make_sound(self):
print("Moo")
cat1 = Cat("Kitty", 2.5)
cow1 = Cow("Fluffy", 4)
for animal in (cat1, cow1):
animal.make_sound()
animal.info()
animal.make_sound()
OUTPUT:

RESULT:
Thus, the output has been successfully executed.
MODULE –6
EX. NO: 6(D)
Create a Class Student with the private members name and age, Add getter and setter to initialize the age variable.

AIM:
To create a Class Student with the private members name and age, Add getter and setter to initialize the age variable.
ALGORITHM:
1. Start the program
2. Creating a class Student .
3. Include private members name,age.
4. Add getter and setter to initialize the age variable.
5. Print the result
6. Stop the program
PROGRAM:
class Student:
def init (self, name, age):
# private member
self.name = name
self. age = age
def get_name(self):
return self.name
def set_name(self,n):
self.name=n
def get_age(self):
return self. age
def set_age(self,a):
self. age=a
stud = Student('Jessa', 14)
print('Name:', stud.get_name(), stud.get_age())
stud.set_age(16)
print('Name:', stud.get_name(), stud.get_age())
OUTPUT:

RESULT:
Thus the output has been successfully executed

MODULE-7
EX. NO:7(A)
Write a Python program to find the sum of first n Natural Numbers
AIM:
To Write a Python program to find the sum of first n Natural Numbers
ALGORITHM:
1. Strat the program
2. Use recursive function to find sum of n natural numbers
3. Print the
result PROGRAM:
def Add(n):
if n==0:
return 0
else:
return n+Add(n-1)
n=int(input())
print("Result is",Add(n))
OUTPUT:
RESULT:
Thus the output has been successfully executed.

MODULE –7
EX. NO:7(B)
Write a Python program to print the sum of digits of a positive number using tail recursion
AIM:
To Write a Python program to print the sum of digits of a positive number using tail recursion
ALGORITHM:
1. Start the program.
2. Use tail recursion to get the sum of the digits of a positive number
3. Print the result
4. End the program.
PROGRAM:
def sum_(n):
if n==0:
return 0
elif n<0:
return "Not defined"
else:
return (n%10)+sum_(n//10)
n=int(input())
print(sum_(n))
OUTPUT:

RESULT:
Thus the output has been successfully executed.

MODULE-7
EX. NO:7(C)
Define the abstract base class named Polygon and also define the abstract method. This
base class inherited by the various subclasses. Implement the abstract method in each
subclass. Create the object of the subclasses and invoke the sides() method.
AIM:
To Define the abstract base class named Polygon and also define the abstract method. This
base class inherited by the various subclasses. Implement the abstract method in each
subclass. Create the object of the subclasses and invoke the sides() method.
ALGORITHM:
1. Start the program
2. Create a abstract class name Polygon
3. Define abstract method
4. Create classes and methods given in the question
5. Print the result
6. End the program
PROGRAM:
OUTPUT:
from abc import ABC
class Polygon(ABC):
def sides(self):
pass

class Triangle(Polygon):
def sides(self):
print("Triangle has 3 sides")
class Pentagon(Polygon):
def sides(self):
print("Pentagon has 5 sides")
class Hexagon(Polygon):
def sides(self):
print("Hexagon has 6 sides")
class square(Polygon):
def sides(self):
print("I have 4 sides")
t = Triangle()
t.sides()
s = square()
s.sides()
p = Pentagon()
p.sides()
k = Hexagon()
k.sides()
OUTPUT:
RESULT:
Thus the output has been successfully executed.

MODULE-7
EX. NO:7(D)
Create a Class Student with the private members name and age ,Add getter and
setter to initialize the age variable.
AIM:
To Create a Class Student with the private members name and age ,Add getter
and setter to initialize the age variable.
ALGORITHM:
1. Start the program.
2. Create a class name Student with private numbers name and age
3. Add get and setter to initialize the age variable
4. Print the result
5. End the
program PROGRAM:
class Student:
def init (self, name,
age): # private member
self.name = name
self. age = age
def
get_name(self):
return self.name
def set_name(self,n):
self.name=n
def get_age(self):
return self. age
def set_age(self,a):
self. age=a
stud = Student('Jessa', 14)
print('Name:', stud.get_name(), stud.get_age())
stud.set_age(16)
print('Name:', stud.get_name(),
stud.get_age()) OUTPUT:
RESULT:
Thus the output has been successfully executed.
MODULE- 8

EX : 8(A)

QUESTION :

The provided code stub reads two strings from STDIN, a and b

AIM:

To provided code stub reads two strings from STDIN, a and b. Add code to print
three lines where:
1. The first line contains the concatenation of the two strings.
2. The second line contains the repetition of the first string 3 times

ALGORITHM:

Step1 : Get two input from the user


Step2 : Add first & second input
Step3 : And Multiply first & second input
Step4 : Execute the program.

PROGRAM:

a=input()
b=input()
print(a+b)
print(a*3)

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 8

EX : 8(B)

QUESTION :

Write a python program to display elements from a list, present at odd index
positions.

AIM:

To construct a python program to display elements from a list, present at odd index
positions

ALGORITHM:

Step1 : Get two input from the user & append to an list
Step2 : a loop can be used to iterate over the elements Step3
: print only the odd numbers
Step4 : Execute the program.

PROGRAM:

size=int(input())
l=[]
for i in range(size):
a=int(input())
l.append(a)
for i in range(0,size):
if i%2!=0:
print(l[i],end=" ")

OUTPUT:

RESULT:
Thus the program has been successfully executed.
MODULE- 8

EX : 8(C)

QUESTION :

The provided code stub reads and integer,n , from STDIN. For all non-
negative integers i > n, print i3

AIM:

To construct python code stub reads and integer,n , from STDIN. For all non-
negative integers i > n, print i3

ALGORITHM:

Step1 : Get two input from the user


Step2 : Append to an list
Step3 : Execute the program.

PROGRAM:

n=int(input())
l=[]
for i in range(n):
l.append(i)
for i in l:
print(i**3)

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 8

EX : 8(D)

QUESTION :

Develop a python program to count the number of vowels and consonants from
the given string

AIM:
To construct a python program to count the number of vowels and consonants
from the given string

ALGORITHM:

Step1 : Get an input from the user


Step2 : Condition to count the numbers of Vowels Step3 :
Condition to count the numbers of Consonants Step4 :
Execute the program.

PROGRAM:

def fun(s):
v,c=0,0
for i in s:
if i in ['A','E','I','O','U','a','e','i','o','u']:
v+=1
else:
c+=1
print("Number of Vowels:",v)
print("Number of Consonants:",c)
s=input()

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 9

EX : 9(A)

QUESTION :

Develop a python program to count the number of vowels and consonants from
the given string

AIM:
To construct a python program to count the number of vowels and consonants
from the given string

ALGORITHM:

Step1 : Get two input from the user Step2


: Condition to print into a matrix Step3 :
print the program
Step4 : Execute the program.

PROGRAM:

def create_matrix(n,m):
M=[]
for i in range(n):
row=[]
for j in range(m):
x=int(input())
row.append(x)
M.append(row)
return M
r,c=input().split()
A=create_matrix(int(r),int(c))
B=create_matrix(int(r),int(c))
C=A+B
print(A)
print(B)
Print(c)
OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 9
EX : 9(B)

QUESTION :

Write a Python class program to generate all even numbers between 200 and 300 and store
in a list using list comprehension.

AIM:

To develop a Python program to generate all even numbers between 200 and 300 and store
in a list using list comprehension.

ALGORITHM:

Step1 : Get an input from the user


Step2 : Condition to check even numbers between 200 - 300 Step3
: store in a list using list comprehension.
Step4 : Execute the program.

PROGRAM:

class Generate:
def init__(self, first,d,last):
self.first = first
self.d = d
self.last=last
def Ap_generate(self):
L=[i for i in range(self.first,self.last+1,self.d)]
return L
Series = Generate(200,2,301)
print(Series.Ap_generate())

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 9

EX : 9(C)

QUESTION :

Find the transpose of a matrix using list Comprehension

AIM:

To develop a Python program to Find the transpose of a matrix using list


Comprehension

ALGORITHM:

Step1 : Get an input from the user


Step2 : Condition to convert number to an matrix
Step3 : Execute the program.

PROGRAM:

def create_matrix(n,m):
M=[]
for i in range(n):
row=[]
for j in range(m):
x=int(input())
row.append(x)
M.append(row)
return M

r,c=input().split()
r=int(r)
c=int(c)
A=create_matrix(r,c)
print(A)
T = [[r[i] for r in A] for i in range(len(A[0]))]
print(T)

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 9

EX : 9(D)

QUESTION :

Write a Python class to perform Insertion sort algorithm

AIM:
To develop a Python class to perform Insertion sort algorithm

ALGORITHM:

Step1 : Get an input from the user


Step2 : Create list
Step3 : Insertion sort
Step4 : Execute the program.

PROGRAM:

class Numbers:
def init__(self, N=0):
self.N = int(input())
def create_list(self):
self.L=[]
for i in range(self.N):
x=int(input())
self.L.append(x)
def sorting(self):
for i in range(1,len(self.L)):
key=self.L[i]
j=i-1
while j>=0 and key < self.L[j]:
self.L[j+1]=self.L[j]
j=j-1
self.L[j+1]=key
def print_List(self):
for i in range(self.N):
print(self.L[i])
L1=Numbers()
L1. create_list()
print('Before Sorting')
L1.print_List()
L1.sorting()
print('After Sorting')
L1.print_List()
OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 10

EX : 10(A)

QUESTION :

Write a python program to push only vowels into the stack from the given
string

AIM:

To develop a python program to push only vowels into the stack from the given
string

ALGORITHM:

Step1 : Get an input from the user.


Step2 : Append to an list.
Step3 : Condition to push only vowels into the stack from the given string. Step4
: Execute the program.

PROGRAM:

l=[ S]
s=input()
for i in s:
if i in ['a','A','e','i','o','u','E','I','O','U']:
l.append(i)
print("".join(l))

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 10

EX : 10(B)

QUESTION :

Write a python program to check whether the given string is palindrome


AIM:

To develop a python program to check whether the given string is palindrome

ALGORITHM:

Step1 : Get an input from the user.


Step2 : whether the given string is palindrome.
Step3 : If palindrome print “yes” or “No” .
Step4 : Execute the program.

PROGRAM:

def ispalidrone(s):
return s==s[::-1]
s=input()
ans= ispalidrone(s) if
ans:
print("Yes")
else:
print("No")

OUTPUT:

RESULT:

Thus the program has been successfully executed.

MODULE- 10
EX : 10(C)

QUESTION :

Write a python program to add only the even unique numbers using appendleft()
from n given numbers

AIM:

To develop a python program to add only the even unique numbers using
appendleft() from n given numbers

ALGORITHM:

Step1 : Get an input from the user.


Step2 : Condition to add only the even unique numbers
Step3 : use appendleft() function
Step4 : Execute the program.

PROGRAM:

from collections import deque


class Queue:
def init (self):
self.queue = deque()
def add_element(self,val):
if val%2==0 and val not in self.queue:
self.queue.appendleft(val)
return True
return False
TheQueue = Queue()
n=int(input())
for i in range(n):
TheQueue.add_element(int(input()))
print(TheQueue.queue)

OUTPUT:
RESULT:

Thus the program has been successfully executed.


MODULE- 10

EX : 10(D)

QUESTION :

Write a python program to get the 4 integer values from user and display the values
using multiprocessing library

AIM:
To develop a python program to get the 4 integer values from user and display
the values using multiprocessing library

ALGORITHM:

Step1 : Get the input from user


Step2 : display the values using multiprocessing library
Step3 : Execute the program.

PROGRAM:

from multiprocessing import Queue


queue = Queue()
list1=[]
for i in range(4):
queue.put(int(input()))
for i in range(4):
print(queue.get())

OUTPUT:

RESULT:
Thus the program has been successfully executed.
MODULE- 11

EX : 11(A)

QUESTION :

Write a function to traverse the linked list and display it in the following format.

AIM:

To develop a python program to traverse the linked list and display it in the
following format.

ALGORITHM:

Step1 : Get the input from the user


Step2 : Condition to print the traverse of a linked list and display it.
Step3 : Enter the condition for loop
Step4 : Execute the program.

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")
list.head.next = e2
e2.next = e3
list.listprint()

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 11

EX : 11(B)

QUESTION :

Write a function to traverse the linked list and display it in the following format.

AIM:

To develop a python program to traverse the linked list and display it in the
following format.

ALGORITHM:

Step1 : Get the input from the user


Step2 : Condition to print the traverse of a linked list and display it.
Step3 : Enter the condition for loop
Step4 : Execute the program.

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")
list.head.next = e2
e2.next = e3
list.listprint()
OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 11

EX : 11(C)

QUESTION :

Write a python function to search an element in the doubly linked list.

AIM:

To develop a python function to search an element in the doubly linked list.

ALGORITHM:

Step1 : Create a new class.


Step2 : Create a constructor containing value data.
Step3 : Check list is empty or not or search for the next element Step4
: Execute the program.

PROGRAM:
class Nodeq:
def init (self, data):
self.data = data
self.next = None
self.prev = None
class DoublyLinkedList:
def init (self):
self.head = None
def insert_beginning(self,data):
new_node = Nodeq(data)
if(self.head == None):
self.head = new_node
return
self.head.prev = new_node
new_node.next = self.head
self.head = new_node
def insert_end(self, new_data):
new_node = Nodeq(new_data) if
self.head is None:
new_node.prev = None
self.head = new_node
return
last = self.head
while last.next:
last = last.next
last.next = new_node
new_node.prev = last
def search(self,data):
temp = self.head
while temp:
if temp.data==data:
break
temp = temp.next
if temp==None:
print("The given data doesnot exist:")
return False
return True
Dllist = DoublyLinkedList()
Dllist.insert_beginning(2)
Dllist.insert_end(0)
Dllist.insert_end(1)
print(Dllist.search(0))
print(Dllist.search(3))

OUTPUT:

RESULT:

Thus the program has been successfully executed.


MODULE- 11

EX : 11(D)

QUESTION :

Write a python function to insert elements at the beginning of the doubly linked
list.

AIM:

To develop Type a python function to insert elements at the beginning of the doubly
linked list.

ALGORITHM:

Step1 : Create a new node. allocate memory for newNode. Step2


: Set prev and next pointers of new node.
Step3 : point next of newNode to the first node of the doubly linked list Step4
: Make new node as head node.Point prev of the first node newNode Step5 :
Execute the program.

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_node
print("node inserted")
return
new_node = Node(data)
new_node.nref = self.start_node
self.start_node.pref = new_node
self.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 successfully executed


MODULE- 12

EX : 12(A)

QUESTION :

Write a python program and display the elements pushed in stack

AIM:

To develop a python program and display the elements pushed in stack

ALGORITHM:

Step1 : Create a new list. Named stack.


Step2 : Append the value of the three element to the stack. Step3
: Print the list
Step4 : Execute the program.

PROGRAM:

stack = []
stack.append('a')
stack.append('b')
stack.append('c')
print('Stack after elements are pushed:')
print(stack)

OUTPUT:

RESULT:

Thus the program has been successfully executed


MODULE- 12

EX : 12(B)

QUESTION :

Type a python code to insert 3 elements. Also check and print the index value of the
elements stored in the stack.

AIM:

To develop python code to insert 3 elements. Also check and print the index value
of the elements stored in the stack.

ALGORITHM:

Step1 : Create a new list. Named stack.


Step2 : Append the value of the three element to the stack. Step3
: Using the for loop get the values of the list.
Step4 : Print the list
Step5 : Execute the program.

PROGRAM:

stack = []
stack.append('a')
stack.append('b')
stack.append('c')
print('Initial stack: ' + str(stack))
for i in range(len(stack)):
print(i, end=" ")
print(stack[i])

OUTPUT:

RESULT: Thus the program has been successfully execute


MODULE- 12

EX : 12(C)

QUESTION :

Type a python code and display all the elements inserted and also display after
deleting the first element.

AIM:

To develop python code and display all the elements inserted and also display after
deleting the first element.

ALGORITHM:

Step1 : Create a new list. Named queue.


Step2 : Append the value of the three element to the queue. Step3
: Delete the first element of queue using pop.
Step4 : Print the queue. Step5 :
Execute the program.

PROGRAM:

queue = []

queue.append('a')
queue.append('b')
queue.append('c')

print('Queue after elements are inserted:')


print(queue)

print('Deleting the first element inserted:')


print(queue.pop(0))
print('Queue after the first elements is deleted:')
print(queue)

OUTPUT:
RESULT:

Thus the program has been successfully executed


MODULE- 12

EX : 12(D)

QUESTION :

Type a python code to insert 3 players in the list. Also check and print the index
value of the players in the list.

AIM:

To develop python code to insert 3 players in the list. Also check and print the index
value of the players in the list.

ALGORITHM:

Step1 : Create a new list. Named queue. Step2 :


Append the 3 players to the queue.
Step3 : check and print the index value of the players in the list. Step4
: Print the queue.
Step5 : Execute the program.

PROGRAM:

queue= []

queue.append('Player_1')

queue.append('Player_2')
queue.append('Player_3')

print('Initial queue: ' + str(queue))

for i in range(len(queue)):
print(i, end=" ")
print(queue[i])

OUTPUT:
RESULT:

Thus the program has been successfully executed

You might also like