PSPP Lab Manual Pgms
PSPP Lab Manual Pgms
Date:
Aim:
Algorithm:
Formula = (n-100)*1.5
Formula BA=100*2+(n-200)*3
Program:
if(n<100):
BA= 0
elif(n<=200):
BA=(n-100)*1.5
elif(n>200):
BA=100*2+(n-200)*3
Start
Yes
If n<=100
? BA=0
No
If Yes
(n>100&n<= BA= BA=(n-
200) ? 100)*1.5
No
Yes
If (n>200)?
BA =100*2+(n-
200)*3
No
Stop
Output:
Electricity Bill: 0
Result:
Thus an algorithmtocalculate electricity bill was written and the flowchart was
developed successfully.
Ex. No. 1(b) Retail Shop Billing
Date:
Aim:
Algorithm:
Program:
Bill_amount = 0,
i=1
for i in range(n):
Start
No
i<=n?
Yes
Calculate Bill_amount =
Bill_amount + (Qt*P)
Print Bill_amount
Stop
Output:
Result:
Thus an algorithmto calculate Retail shop bill was written and the flowchart was
developed successfully.
Ex. No. 1(c) Sin Series
Date:
Aim:
Algorithm:
Sin(X) = (X^1/1!)-(X^3/3!)+(X^5/5!)-(X^7/7!)+…….
t=x,
sum=x
import math
def sin(x,n):
sine = 0
foriin range(n):
sign = (-1)**i
pi=22/7
y=x*(pi/180)
return sine
print(round(sin(x,n),2))
Flowchart:
Output:
0.5
Result:
Thus an algorithmto implement the sin series was written and the flowchart was
developed successfully.
Ex. No. 1(e) Weight of a Steel Bar
Date:
Aim:
Algorithm:
Program:
W = D*V
Start
Calculate Weight
W =D*V
Stop
Output:
Result:
Thus an algorithmto calculate weight of a steel bar was written and the flowchart was
developed successfully.
Ex. No. 1(f) Compute Electrical Current in Three Phase AC Circuit
Date:
Aim:
Algorithm:
I = P/ (√3 x VL x Cos Ф)
Program:
PF = 1
I = P/ (√3 x VL x PF)
Start
Stop
Output:
Result:
Date:
Aim:
To implement a python program to exchange the values of two variables using simple
statements and expressions
Algorithm:
Step 2: Get two integer inputs a and b from the user using the input() function.
Step 3: Swap the values of variables directly using the formula (a, b) = (b, a)
Flowchart:
Program:
print("Before swapping")
print(a,b)
(a,b)=(b,a)
print("After swapping")
print(a,b)
Output:
Result:
Thus the Python program to exchange the values of two variables using simple
statements and expressions was written, executed and the output was verified successfully.
Ex. No. 2(b) Circulate the Values of n Variables
Date:
Aim:
Algorithm:
A) Pop the first value and append to the last in the list
Step 6: Repeat the step 5 until all the values are circulated
Flowchart:
Program:
#Read values
list1 = []
forval in range(0,no_of_terms,1):
list1.append(ele)
forval in range(0,no_of_terms,1):
ele = list1.pop(0)
list1.append(ele)
print(list1)
Output:
Result:
Thus the Python program to circulate the values of n variables using simple
statements and expressionswas written, executed and the output was verified successfully.
Ex. No. 2(c) Distance between Two Points
Date:
Aim:
To implement a python program to find the distance between two points using simple
statements and expressions
Algorithm:
Step 3: Compute the distance using the formula √(𝑥2 − 𝑥1)2 + (𝑦2 − 𝑦1)2
Flowchart:
Program:
x1=int(input("enter x1 : "))
y1=int(input("enter y1 : "))
x2=int(input("enter x2 : "))
y2=int(input("enter y2 : "))
Output:
Result:
Thus the Python program to find the distance between two points using simple
statements and expressions was written, executed and the output was verified successfully.
Ex. No. 3(a) Conditionals and Iterative Loops –NumberSeries –
Fibonacci Series
Date:
Aim:
To implement a python program to find the Fibonacci Series of n terms using simple
conditionals and iterative loops
Algorithm:
Step 2: Get the input value from the user to calculate the Fibonacci series
Step 4: Check
Program:
n1, n2 = 0, 1
count = 0
ifnterms<= 0:
elifnterms == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
Output:
Result:
Thus the Python program to find the Fibonacci Series of n terms using simple
conditionals and iterative loops was written, executed and the output was verified
successfully.
Ex. No. 3(b) Number Pattern – Simple Pattern
Date:
Aim:
To implement a python program to find the Number Pattern using simple conditionals
and iterative loops
Algorithm:
Step 4: Inner loop will print the value of I after each iteration
# Number Pattern
depth = 6
fori in range(number):
Output:
Result:
Thus the Python program to find the Number Pattern using simple conditionals and
iterative loops was written, executed and the output was verified successfully.
Ex. No. 3(c) Number Pattern – Pascal’s Triangle
Date:
Aim:
To implement a python program to find the Number Pattern for Pascal’s Triangle
using simple conditionals and iterative loops
Algorithm:
Step 2: Taking input from the user to get the number of rows.
Step 4: Using for loop, which will iterate through 0 to n - 1, append the sub-lists to the
list.
Step 6: Now, use for loop to define the value of the number inside the triangle
adjacent row.
# Pascal Triangle
fori in range(num):
list1.append([])
list1[i].append(1)
if(num != 0):
list1[i].append(1)
fori in range(num):
print(" " * (num - i), end = " ", sep = " ")
print()
Output:
Result:
Thus the Python program to find the Number Pattern for Pascal’s Triangle using
simple conditionals and iterative loops was written, executed and the output was verified
successfully.
Ex. No. 3(d) Pyramid Pattern – Triangle Pattern
Date:
Aim:
To implement a python program to print the triangle pyramid pattern using simple
conditionals and iterative loops
Algorithm:
Step 2: Initialize the variable n to enter the number of rows for the pattern
Step 3: Compute m = (2 * n) – 2
Flowchart:
Start
Program:
m = (2 * n) - 2
print(end=" ")
print(" ")
Output:
Result:
Thus the Python program to print the triangle pyramid pattern using simple
conditionals and iterative loops was written, executed and the output was verified
successfully.
Ex. No. 4(a) Operations of List - Items Present in a Library,
Components of a Car, Materials Required for Construction of a Building
Date:
Aim:
To implement a python program to do the operations of list for the items present in a
library, components of a car and materials required for construction of a building
Algorithm:
Step 4: Get the materials required for construction of a building in the form of list
Program:
print ("Item you needed from library is available. Visit library to collect it")
else:
if item in carlist2:
else:
if item in constructionlist3:
else:
print (liblist1)
liblist1.extend(['e-books'])
print (constructionlist3)
print (liblist1)
print (carlist2)
import copy
Thus the Python program to implement the operations of list for the items present in a
library, components of a car and materials required for construction of a buildingwas written,
executed and the output was verified successfully.
Ex. No. 4(b) Operations of Tuple - Items Present in a Library,
Components of a Car, Materials Required for Construction of a Building
Date:
Aim:
To implement a python program to do the operations of tuple for the items present in
a library, components of a car and materials required for construction of a building
Algorithm:
Step 4: Get the materials required for construction of a building in the form of tuple
Program:
print ("Item you needed from library is available. Visit library to collect it")
else:
if item in cartuple2:
else:
if item in constructiontuple3:
else:
Thus the Python program to implement the operations of tuple for the items present in
a library, components of a car and materials required for construction of a building was
written, executed and the output was verified successfully.
Ex. No. 5(a) Operations of Sets – Language, Components of an
automobile, Elements of a Civil Structure
Date:
Aim:
Algorithm:
Step 4: Get the elements of a civil structure as input in the form of set
Program:
languages = {"c", "c++", "c#", "java", "javascript", "php", "python", "ruby" "pearl",
"html"}
if keyword in automobile:
print ("Component you looking in a car is available")
else:
if keyword in construction:
else:
if keyword in languages:
else:
print(languages)
Thus the Python program to implement the operations of sets for languages,
components of an automobile and elements of a civil structurewas written, executed and the
output was verified successfully.
Ex. No. 5(b) Operations of Dictionaries – Language, Components of
an automobile, Elements of a Civil Structure
Date:
Aim:
Algorithm:
Step 4: Get the elements of a civil structure as input in the form of dictionary
Program:
else:
if keyword in construction:
else:
if keyword in languages:
else:
Output:
Result:
Thus the Python program to implement the operations of dictionaries for languages,
components of an automobile and elements of a civil structure was written, executed and the
output was verified successfully.
Ex. No. 6(a) Finding the Factorial of a Number – Using Functions
Date:
Aim:
Algorithm:
Main function:
Step 4: if (num>0):
Step 4.1: Display “Factorial does not exist for negative numbers” go to step 5
Step 6: Else
Sub Function:
Step 2: Declare n
Step 3: if (n == 1)
Step 3.1: Return the value of n
Step 4: else
Step 5: Return
Flowchart:
Program:
def recur_factorial(n):
if n == 1:
return n
else:
if num < 0:
elif num == 0:
print("The factorial of 0 is 1")
else:
Output:
Result:
Thus the Python program to find the factorial of a given number using functions was
written, executed and the output was verified successfully.
Ex. No. 6(b) Finding the largest Number in a List – Using Functions
Date:
Aim:
Algorithm:
Main function:
Step 3.1: Display “Please enter the Total Number of List Elements”
Sub function:
Step 6: Return
Flowchart:
Start
def
max_num_in_list(list)
Program:
list = []
list.append(value)
print(list)
def max_num_in_list(list):
max = list[0]
for a in list:
if a > max:
max = a
return max
print(max_num_in_list(list))
Output:
Result:
Thus the Python program to find the largest number in a list using functions was
written, executed and the output was verified successfully.
Ex. No. 6(c) Finding the Area of Shapes – Using Functions
Date:
Aim:
Algorithm:
Step 4: Use the formulas to find the area of square, rectangle, circle, triangle and
parallelogram
Flowchart:
Program:
def calculate_area(name):
name = name.lower()
if name == "rectangle":
rect_area = l * b
sqt_area = s * s
print(f"The area of square is {sqt_area}.")
tri_area = 0.5 * b * h
pi = 3.14
circ_area = pi * r * r
else:
# driver code
if __name__ == "__main__" :
shape_name = input("Enter the name of shape whose area you want to find: ")
# function calling
calculate_area(shape_name)
Output:
Result:
Thus the Python program to find the area of shapes using functions was written,
executed and the output was verified successfully.
Ex. No. 7(a) Finding the Reverse of the Elements of a String
Date:
Aim:
Algorithm:
Step 6.2: i = i – 1
Program:
def reverse_string(str2):
str1 = i + str1
return str1 # It will return the reverse string to the caller function
Output:
Result:
Thus the Python program to find the reverse of the elements of a string was written,
executed and the output was verified successfully.