PSP Final For Print
PSP Final For Print
PSP Final For Print
(Autonomous)
KOMARAPALAYAM – 637303
Regulation R2023
I YEAR/I SEMESTER
PREPARED BY APPROVED BY
Page
Ex. Date Name of the Experiment Marks Sign
No No
Write a algorithm & draw flowchart for simple
1
computational problems
Write a program to perform different arithmetic
2
operations on numbers in python.
Write a python program to implement the various
3
control structures
Write a python program for computational problems
4
using recursive function.
(Autonomous)
KOMARAPALAYAM
VISION
MISSION
(Autonomous)
KOMARAPALAYAM
VISION
MISSION
(Autonomous)
KOMARAPALAYAM
PEO 1. To educate the students for acquiring sound knowledge in the field of
Electronics and Communication Engineering and interdisciplinary field, so as to meet
the needs in the field of Electronics and Communication industries.
PEO 2. To provide knowledge and skills for developing new products in the
field of Electronics and communication.
PEO 5. To expose the students on professional, ethical and social skills to shape them
with leadership quality for analyzing and solvingengineering and social issues.
EXCEL ENGINEERING COLLEGE
(Autonomous)
KOMARAPALAYAM
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling of complex
engineering activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
7. Environment and Sustainability: Understand the impact of the professional
engineering solutions to societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
12. Lifelong learning: Recognize the need for and have the preparation and ability to
engage in independent and lifelong learning in the broadest context of technological
change.
EXCEL ENGINEERING COLLEGE
(Autonomous)
KOMARAPALAYAM
2. Design Principles and Best practices: To apply design principles and best practices
fordeveloping quality products for science and business applications.
Algorithm:
1. Read one input value using input function
2. Convert it into float
3. Find the square root of the given number using the formula input value ** 0.5
4. Print the result
5. Exit.
Flow Chart:
Start
X=float(A)
C=X**0.5
Stop
Program:
Output:
enter a number: 676
square root: 26.0
Output:
32.0
Result
Thus the Flowchart for to find square root of a number is executed successfully
and output is verified.
1b. Compute the GCD of two numbers
Aim:
Algorithm:
Flow Chart:
Finding HCF of a number:
GCD = 1
for i in range(2,n1+1):
if(n1%i==0 and n2%i==0):
GCD = i
Output:
Result:
Thus the flowchart for compute GCD of two numbers is executed successfully and output is verified.
1C Compute to find Odd natural Numbers
Aim:
To compute odd natural numbers
Algorithms:
Step 1: Start
Step 2: Declare x as an integer variable.
Step 3: Set x=0
Step 4: Determine the value of n in integers.
Step 5: While (x<=n), repeat steps 5–7.
Step 6: if (x%2 != 0)
Step 7: then print x
Step 8 : x=x+1
Step 9: Stop
Flowchart:
Programs:
Output:
Enter a number:10 1
3
5
7
9
11
13
15
17
19
Result:
Thus the flowchart for compute odd natural numbers is executed successfully and output is verified.
1D . To find the sum of any five integers
Aim :
To find the sum of any five integers
Algorithms:
Step 1: Start
Step 2: Read number n
Step 3: Declare sum to 0 and i to 1
Step 4: Repeat steps 5 to 7 until i<=n
Step 5: update sum as sum = sum + i
Step 6: increment i
Step 7: Print sum
Step8: Stop Output: sum
Flowchart:
Programs :
Output:
Viva Questions:
1. What is an algorithm?
2. What is the need for an algorithm?
3. What is the Complexity of Algorithm?
4. What are the building blocks of an algorithm?
5. Classify the three types of statements.
Result:
Thus the flowchart for Sum of n natural numbers is executed successfully and output is verified.
Exp No.2 Write a program to perform different arithmetic operations on numbers in python
Aim:
Algorithm:
Step1: Start
Step2: Read the input num1, num2
Step3: calculate the addition, subtraction, multiplication, division from Inputs
Step4: Display the Result
Step6: Stop
Example 1
num1 = float(input(" Please Enter the First Value Number 1: "))
num2 = float(input(" Please Enter the Second Value Number 2: "))
Output:
Example 2:
num = int (input("enter a number:"))
Output:
num = 10
The number is 46
Example 3:
num = num%3 *5
print(“The number is”, num)
Output:
num = 5
The number is 10
Example 4:
num =(num+3*5)-4
print(“The number is”, num)
Output:
num = 15
The number is 24
Viva Questions:
1. What is an Operator in general?
Result:
Thus the program to perform different arithmetic operations on numbers is executed
successfully and output is verified.
Exp No.3 Write a python program to implement the various control structures
Aim:
To find a maximum value in a given list using python program
Algorithm:
STEP 1 Start the program
STEP 2 Read the no of terms in the list as n
STEP 3 Read the list values from 1 to n
STEP 4 Initialize max =0
STEP 5 Initialize i=1 repeat step 6 until n
STEP 6 If list[i]> max
STEP 7 Set max = list[i]
STEP 8 Print Maximum numbers as max
STEP 9 Stop the program.
Program:
#input size and elments of an array
n=int(input("Enter no of terms:"))
list1=[]
print("Enter the Numbers\n")
for i in range(n):
list1.append(int(input ()))
#initialize the greatest value
Max =0
#Find the greatest value
for i in range(n):
if list1[i]>Max:
Max=list1[i]
# Print the greatest Number
print("Greatest Number is ", Max)
Output
Result:
Thus the program to find the maximum value in a list is executed successfully and
output is verified
Example 2
Aim :
Algorithms:
Step 1: Start
Step 2: Declare a Input a num
Step 3 : if num %2==0
Step 4 : print Even number
Step 5 : Else
Step 6: Print Odd Numbers
Step 7: Stop
Programs:
Output:
Enter a number : 6
Even Number
Viva Questions:
Result :
Thus the odd or even of given numbers is executed and verified Successfully
Exp No.4 Write a python program for computational problems using recursive function
Example 1
Aim:
To write python program to find Factorial of Number using recursion.
Algorithm:
1. Start the program.
2. Read the number to find the factorial.
3. Get a number for a user for num.
4. Check if the number is negative, positive or zero,ie.:num<0
5. If num is equal to zero print a factorial of 0 is1,
6. now check given number is factorial for i in range(1,num+1)
7. factorial = factorial*i
8. print factorial of num
Program:
factorial = 1
Example 2:
Aim:
To write python program to find sum of natural Number using recursion.
Algorithm:
1. Start a programs
2. Initialize the required variables.
3. Define a recursive function with base case as number ==0.
4. Set the step recursive call as number + recursum( number – 1 ).
5. Call the recursive function recursum() and print the returned value.
6. End of Program
Program:
def recursum(number):
if number == 0:
return number
return number + recursum(number-1)
number = int(input("enter a number :"))
sum= 0
result = recursum(number)
print("The Recursive sum of Natural number is", result)
Output:
Enter a number : 6
The Recursive sum of Natural number is 21
Viva Questions:
1. What is Recursion?
2. List the need of Recursion.
3. Name the Properties of Recursion.
4. How the recursive functions stored in memory?
5. What is the base condition in recursion?
Result:
Thus the program for computational problems using recursive function is executed
successfully and output is verified.
Exp No.5 Demonstrate use of list for data validation
Aim:
To demonstrate use of list for data validation.
Program:
Adding Element to a List
# animals list
animals = ['cat', 'dog', 'rabbit']
# 'guinea pig' is appended to the animals list
animals.append('guinea pig')
Output
# animals list
animals = ['cat', 'dog', 'rabbit']
# list of wild animals
wild_animals = ['tiger', 'fox']
# appending wild_animals list to the animals list
animals.append(wild_animals)
print('Updated animals list: ', animals)
Output
# random list
random = ['a', ('a', 'b'), ('a', 'b'), [3, 4]]
# count element ('a', 'b')
count = random.count(('a', 'b'))
# print count
print("The count of ('a', 'b') is:", count)
# count element [3, 4]
count = random.count([3, 4])
# print count
print("The count of [3, 4] is:", count)
Output
# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']
# index of 'e' in vowels
index = vowels.index('e')
print('The index of e:', index)
# element 'i' is searched
# index of the first 'i' is returned
index = vowels.index('i')
print('The index of i:', index)
Output
The index of e: 1
The index of i: 2
Viva Questions:
Result:
Thus the program for the use of list for data validation is executed successfully and
output is verified.
Exp No.6 Develop a python program to explore string functions to print reverse words of string
Aim:
To develop a python program to explore string functions to print reverse words of string.
Algorithm:
1. Initialize the string.
2. Split the string on space and store the resultant list in a variable called word.
3.Reverse the list words using reversed function.
4. Convert the result to list.
Program:
# Then, reverse the split string list and join using space
reverse_sentence = ' '.join(reversed(words))
if __name__ == "__main__":
input_str = 'geeks quiz practice code'
print(rev_sentence(input_str))
Output:
Viva Questions:
Result:
Thus the program for the use of list for data validation is executed successfully and
output is verified.
Exp No.7a Implement linear search and binary search
Aim:
Algorithm:
4. Else increment the position and repeat step 3 until pos reaches the length of the list
Program:
lst = []
print("List:", lst)
i = flag = 0
if flag == 1:
print(f"The number {x} is found at index {i}.")
else:
print(f"The number {x} is not in the list.")
Output:
Enter an element: 21
Enter an element: 34
Enter an element: 57
Enter an element: 98
Enter an element: 34
Enter an element: 56
Enter an element: 79
Result:
Thus the Python Program to perform linear search is executed successfully and the
output is verified.
Exp No.7b Implement binary search
Aim:
Algorithm:
Program:
def search(list1, key):
low = 0
high = len(list1) - 1
found = False
if found:
print("Key is found.")
else:
print("Key is not found.")
list1 = [23, 1, 4, 2, 3]
list1.sort()
print(list1)
key = int(input("Enter a key element: "))
search(list1, key)
Output:
[1, 2, 3, 4, 23]
Enter a key element: 3
key is found
Viva Questions:
Result:
Thus the Python Program to perform binary search is executed successfully and the
output is verified.
Exp No.8 Develop a python program to implement sorting methods
Example 1
Aim:
Algorithm:
2. Initialise pos=0
4. Set pos=location
Program:
list1=[23,1,4,2,3]
print(list1)
for i in range(len(list1)):
min_val = min(list1[i:])
min_ind = list1.index(min_val)
temp= list1[i]
list1[i]=list1[min_ind]
list1[min_ind]=temp
print(list1)
Output:
[23, 1, 4, 2, 3]
[1, 23, 4, 2, 3]
[1, 2, 4, 23, 3]
[1, 2, 3, 23, 4]
[1, 2, 3, 4, 23]
[1, 2, 3, 4, 23]
[1,2,3,4,23]
Viva Questions:
1. Define sorting in python.
2. How do you sort marks in Python?
3. What is sort () and sorted () in Python?
4. How does Python sort words?
5. Classify the types of sorting.
Result:
Thus the Python Program to perform selection sort is successfully executed and the
output is verified.
Example 2
Aim:
Algorithm:
Program:
def Insertion(my_list):
for index in range(1, len(my_list)):
current_element = my_list[index]
pos = index
my_list[pos] = current_element
list1 = [2, 4, 3, 5, 1]
Insertion(list1)
print("The Insertion Sorted elements are", list1)
Output:
Result:
Thus the Python Program to perform Insertion sort is successfully executed and theoutput is verified
Exp No.9 Develop python programs to perform operations on dictionaries
Aim:
To develop python programs to perform operations on dictionaries.
Program:
Output:
Empty Dictionary:
{}
Viva Questions:
Result:
Thus the program to perform operations on dictionaries is executed successfully and
output is verified.
Exp No.10 Write a python program to read and write into a file
Aim:
To write a Python program to find the most frequent words in a text read from a file.
Algorithm:
Program:
Output:
Hello
This is Delhi
This is Paris
This is London
is Hello
Hello
Th
Hello
['Hello \n', 'This is Delhi \n', 'This is Paris \n', 'This is London \n']
Viva Questions:
Result:
Thus the program to perform operations on dictionaries is executed successfully and
output is verified.
Exp No.11 Create a game activity using Pygame like bouncing ball, car race etc.
Aim:
Viva Questions:
1. What is Pygame?
2. How does Pygame is related to game development in Python?
3. Mention the way of Pygame initialization.
4. What is the game loop?
5. Why game loop is essential in game development with Pygame?
Result:
Thus the program to perform to create a game activit y using Pygames is executed successfully
and output is verified.