Pspp Lab Manual
Pspp Lab Manual
YEAR/SEM : I/I
REGULATION : 2021
Vision
global market.
Mission:
Information Technology
transfer
C)COUNTING
B) RETAILCHARACTER IN A STRING
SHOP BILLING
7
D)REPLACING
C) WEIGHT OF CHARACTERS
A STEEL BAR IN A STRING
1
A)
D) PANDAS
COMPUTE ELECTRICAL CURRENT IN 3 PHASE AC
CIRCUIT
B) NUMPY
A) PROGRAMS USING SIMPLE STATEMENTS EXCHANGE
8
THE
C) VALUES OF TWO VARIABLES
MATPLOTLIB
B) SCIPY
D) CIRCULATE THE VALUES OF N VARIABLES
2
C) DISTANCE BETWEEN TWO VARIABLES
9 A) COPY FROM ONE FILE TO ANOTHER
A) PROGRAMS USING CONDITIONALS & ITERATIVE LOOPS
B) WORD SERIES
NUMBER COUNT FROM A FILE
11
5 B) OPERATIONS
EXPLORING OF DICTIONARY
PYGAME ELEMENTS OF A CIVIL
INSTALLATION
STRUCTURE
PROGRAMS USING FUNCTIONS
12 GAME ACTIVITY
A) FACTORIAL OFUSING PYGAME BOUNCING BALL
A NUMBER
1. A) ELECTRICITY BILLING
AIM:
To write a python program for implementing electricity billing.
ALGORITHM:
START
IF
Units<=100
PayAmount=units*1.5
elif
unit<=200
PayAmount=(100*1.5)+(units-
100)*2.5
elif
unit<=300
PayAmount=(100*1.5)+(200-
100)*2.5+(units-200)*4
elif
unit<=350
PayAmount=(100*1.5)+(200-
100)*2.5+(300-200)*4+(units-300)*5
PayAmount=1500
STOP
#program for calculating electricity bill in Python
if(units<=100):
payAmount=units*1.5
elif(units<=200):
payAmount=(100*1.5)+(units-100)*2.5
elif(units<=300):
payAmount=(100*1.5)+(200-100)*2.5+(units-200)*4
elif(units<=350):
payAmount=(100*1.5)+(200-100)*2.5+(300-200)*4+(units-300)*5
else:
payAmount=1500
Total=payAmount;
OUTPUT:
Electricity bill=200.00
1.B) RETAIL SHOP BILLING
AIM:
To write a python program for implementing retail shop billing.
ALGORITHM:
FLOWCHART:
START
Assign tax=0.18
Assign rate={“Pencil”:10,”Pen”:20,
”Scale”:7,”A4Sheet”:150}
Read quantity of
all items from user
Calculate cost=Pencil*Rate[“Pencil”]
+Pen*Rate[“Pen”]+Scale*Rate[“Scale”]
+A4Sheet*Rate[A4Sheet]
Calculate Bill=cost+cost*tax
Print Bill
Rate={"Pencil":10,"Pen":20,"Scale":7,"A4Sheet":150}
Pencil=int(input("Pencil:"))
Pen=int(input("Pen:"))
Scale=int(input("Scale:"))
A4Sheet=int(input("A4Sheet:"))
cost=Pencil*Rate["Pencil"]+Pen*Rate["Pen"]+Scale*Rate["Scale"]
+A4Sheet*Rate["A4Sheet"]
Bill=cost+cost*tax
OUTPUT:
Pencil:5
Pen:2
Scale:2
A4Sheet:1
Please pay Rs.299.720000
AIM:
To write a python program to calculate weight of a steel bar.
ALGORITHM:
FLOWCHART:
START
Read
Diameter (D)
Calculate
Weight=(D*D)/162
Print Weight
STOP
#program for calculating weight of a steel bar in Python
Weight=(D*D)/162
OUTPUT:
AIM:
To write a python program to calculate electrical current in 3 phase AC circuit.
ALGORITHM:
FLOWCHART:
START
Read Volts,
Amperes
Calculate
power=√ 3 * Volts*Amperes
Print power
STOP
#program for calculating electrical current
import math
power=math.sqrt(3)*volts*amperes
OUTPUT:
AIM:
To write a python program to exchange the values of two variables.
ALGORITHM:
PROGRAM:
def exchange(x,y):
x,y=y,x
print("x =",x)
print("Y= ",y)
print("x =",x)
print("Y= ",y)
exchange(x,y)
OUTPUT:
Enter value of X 85
Enter value of Y 63
AIM:
To write a python program to circulate the values of n variables.
ALGORITHM:
PROGRAM:
def circulate(A,N):
for i in range(1,N+1):
B=A[i:]+A[:i]
print("Circulation",i,"=",B)
return
A=[91,92,93,94,95]
N=int(input("Enter n:"))
circulate(A,N)
OUTPUT:
Enter n:5
('Circulation', 1, '=', [92, 93, 94, 95, 91])
('Circulation', 2, '=', [93, 94, 95, 91, 92])
('Circulation', 3, '=', [94, 95, 91, 92, 93])
('Circulation', 4, '=', [95, 91, 92, 93, 94])
('Circulation', 5, '=', [91, 92, 93, 94, 95])
AIM:
To write a python program to calculate distance between 2 variables.
ALGORITHM:
PROGRAM:
import math
x1 = int(input("Enter a x1: "))
y1 = int(input("Enter a y1: "))
x2 = int(input("Enter a x2: "))
y2 = int(input("Enter a y2: "))
distance = math.sqrt(((x2-x1)**2)+((y2-y1)**2))
print("Distance = %.2f"%distance)
OUTPUT:
Enter a x1: 50
Enter a y1: 50
Enter a x2: 320
Enter a y2: 320
Distance = 381.84
AIM:
To write a python program to calculate 12+22+32+….+N2.
ALGORITHM:
PROGRAM:
OUTPUT:
Enter a number: 5
('Sum = ', 55)
ALGORITHM:
PROGRAM:
OUTPUT:
12
123
1234
12345
AIM:
To write a python program to print number pattern.
ALGORITHM:
1. Start the program
2. Read the number of rows to print from user
3. Print the pyramid pattern using for loops
4. Stop the program
PROGRAM:
print("Print equilateral triangle Pyramid using asterisk symbol ")
size =input("Enter no.of rows:")
m = (2 * size) - 2
for i in range(0, size):
for j in range(0, m):
print(" "),
m=m-1
for j in range(0, i + 1):
print("* "),
print(" ")
OUTPUT:
Print equilateral triangle Pyramid using asterisk symbol
*
* *
* * *
* * * *
* * * * *
AIM:
To write a python program to implement operations in a library list
ALGORITHM:
6. Start the program
7. Declare variable library to list the items present in a library
8. Do the operations of list like append, pop, sort, remove, etc on the list
9. Print the result
10.Stop the program
PROGRAM:
library
=['Books','Periodicals','Newspaper','Manuscripts','Maps','Prints','Documents','Ebooks']
# printing the complete list
print('Library: ',library)
library.append('Audiobooks')
library.sort()
library.remove('Maps')
library.insert(2, 'CDs')
OUTPUT:
('Library list after append Audiobooks: ', ['Books', 'Periodicals', 'Newspaper', 'Manuscripts',
'Maps', 'Prints', 'Documents', 'Ebooks', 'Audiobooks'])
("index of 'Newspaper': ", 2)
('after insert CDs: ', ['Audiobooks', 'Books', 'CDs', 'Documents', 'Ebooks', 'Manuscripts',
'Newspaper', 'Periodicals'])
COMPONENTS OF A CAR
AIM:
To write a python program to implement operations in a car tuple
ALGORITHM:
1. Start the program
2. Declare a tuple variable car to list the components of a car
3. Print the elements of tuple
4. Stop the program
PROGRAM:
('Components of a car: ', ('Engine', 'Battery', 'Alternator', 'Radiator', 'Steering', 'Break', 'Seat
Belt'))
COMPONENTS OF AN AUTOMOBILE
AIM:
To write a python program to implement operations on an automobiles set.
ALGORITHM:
1. Start the program
2. Declare set variables car and motorbike to list the components of a car and motorbike
3. Do the set operations union, intersection, difference and symmetric difference
4. Print the result
5. Stop the program
PROGRAM:
#union operation
#intersection operation
#difference operation
#Symmetric difference
('Components of Car: ', set(['Engine', 'Alternator', 'Radiator', 'Seat Belt', 'Battery', 'Break',
'Steering']))
('Union of car and motorbike: ', set(['Engine', 'Alternator', 'Gear', 'Radiator', 'Seat Belt',
'Battery', 'Fuel tank', 'Break', 'Wheels', 'Steering']))
('Symmetric difference operation: ', set(['Alternator', 'Gear', 'Radiator', 'Seat Belt', 'Battery',
'Fuel tank', 'Wheels', 'Steering']))
AIM:
To write a python program to implement operations of dictionary.
ALGORITHM:
1. Start the program
2. Declare a dictionary building to list the elements of a civil structure
3. Do the dictionary operations add, update, pop and length
4. Print the result
5. Stop the program
PROGRAM:
building={1:'foundation',2:'floor',3:'beams',4:'columns',5:'roof',6:'stair'}
#Elements in dictionary
#length of a dictionary
building.update({6:'lift'})
building[7]='window'
building.pop(3)
('After updation of stair as lift: ', {1: 'foundation', 2: 'floor', 3: 'beams', 4: 'columns', 5: 'roof',
6: 'lift'})
('After adding window: ', {1: 'foundation', 2: 'floor', 3: 'beams', 4: 'columns', 5: 'roof', 6: 'lift',
7: 'window'})
('After removing element beams from building: ', {1: 'foundation', 2: 'floor', 4: 'columns', 5:
'roof', 6: 'lift', 7: 'window'})
a. FACTORIAL OF A NUMBER
AIM:
To write a python program to calculate the factorial of a number.
ALGORITHM:
def fact(n):
if n==1:
return n
else:
return n*fact(n-1)
OUTPUT:
Enter a number: 6
AIM:
To write a python program to find the largest number in a list.
ALGORITHM:
1. Start the program
2. Read number of elements from user
3. Read the elements of list using for loop
4. Find the largest element from list using max() function
5. Print the result
6. Stop the program
PROGRAM:
def maximum(list):
return max(list)
list=[]
n=int(input("Enter no.of elements:"))
print("Enter",n,"elements")
i=0
for i in range(0,n):
element=int(input())
list.append(element)
print("Largest element is:",maximum(list))
OUTPUT:
Enter no.of elements:5
('Enter', 5, 'elements')
65
78
52
99
56
('Largest element is:', 99)
6 c. AREA OF SHAPES
AIM:
To write a python program to find the area of shapes.
ALGORITHM:
1. Start the program
2. Get the choice from user
3. If choice is 1, read radius and calculate area of circle
4. If choice is 2, read side value and calculate area of square
5. If choice is 3, read length and breadth value and calculate area of rectangle
6. If choice is 4, read breadth and weight value and calculate area of triangle
7. Print the result
8. Stop the program
PROGRAM:
def circle():
r=float(input("Enter r value:"))
return 3.14*r*r
def square():
a=float(input("Enter a value:"))
return a*a
def rectangle():
l=float(input("Enter l value:"))
b=float(input("Enter b value:"))
return l*b
def triangle():
b=float(input("Enter b value:"))
h=float(input("Enter h value:"))
return 0.5*b*h
if choice==1:
print("Area of circle is %.2f" %circle())
elif choice==2:
print("Area of square is %.2f" %square())
elif choice==3:
print("Area of rectangle is %.2f" %rectangle())
elif choice==4:
print("Area of triangle is %.2f" %triangle())
else:
print("invalid input")
OUTPUT:
select shape to calculate area:
1.Circle
2.Square
3.Rectangle
4.Triangle
enter choice(1/2/3/4) : 1
Enter r value:5
Area of circle is 78.50
enter choice(1/2/3/4): 3
Enter l value:8
Enter b value:9
Area of rectangle is 72.00
a. REVERSE OF A STRING
AIM:
To write a python program to reverse a string
ALGORITHM:
PROGRAM:
s=input("Enter a string:")
OUTPUT:
AIM:
To write a python program to check whether a string is palindrome or not
ALGORITHM:
PROGRAM:
s1=input("Enter a string:")
s2=s1[::-1]
if list(s1)==list(s2):
print("It is a palindrome")
else:
OUTPUT:
AIM:
To write a python program to count number of characters in a string
ALGORITHM:
PROGRAM:
OUTPUT:
Enter a string: "I love python programming, python is very interesting subject"
Enter a character/substring to count: 'python'
('The no.of times', 'python', 'occurred is:', 2)
AIM:
To write a python program to replace characters in a string
ALGORITHM:
1. Start the program
2. Read a string from user
3. Read old string
4. Read new string to replace
5. Replace the old string with new string using replace() method
6. Print the result
7. Stop the program
PROGRAM:
OUTPUT:
Enter any string: 'Problem solving and python programming'
Enter old string: 'python'
Enter new string: 'C'
Problem solving and C programming
8.A) PANDAS
AIM:
To write a python program to compare the elements of the two Pandas Series using
Pandas library.
PROGRAM:
import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 10])
print("Series1:")
print(ds1)
print("Series2:")
print(ds2)
print("Compare the elements of the said Series:")
print("Equals:")
print(ds1 == ds2) print("Greater
than:") print(ds1 > ds2) print("Less
than:")
print(ds1 < ds2)
OUTPUT:
Series1:
0 2
1 4
2 6
3 8
4 10
dtype: int64
Series2:
0 1
1 3
2 5
3 7
4 10
dtype: int64
Compare the elements of the said Series:
Equals:
0 False
1 False
2 False
3 False
4 True
dtype: bool
Greater than:
0 True
1 True
2 True
3 True
4 False
dtype: bool
Less than:
0 False
1 False
2 False
3 False
4 False
dtype: bool
8.B) NUMPY
AIM:
To write a program to test whether none of the elements of a given array is zero
using NumPy library.
ALGORITHM:
1. Start the program
2. Import numpy from python standard library
3. Declare an array and print the original array
4. Test whether none of the elements of the array is zero or not
5. If it contains zero print False otherwise print True
6. Stop the program
PROGRAM:
import numpy as np
x = np.array([1, 2, 3, 4])
print("Original array:")
print(x)
print("Test if none of the elements of the said array is zero:")
print(np.all(x))
x = np.array([0, 1, 2, 3])
print("Original array:")
print(x)
print("Test if none of the elements of the said array is zero:")
print(np.all(x))
OUTPUT:
Original array:
[1 2 3 4]
Test if none of the elements of the said array is zero: True
Original array:
[0 1 2 3]
Test if none of the elements of the said array is zero: False
8.C) MATPLOTLIB
AIM:
To write a python program to plot a graph using matplotlib library.
ALGORITHM:
1. Start the program
2. Import matplotlib from python standard library
3. Declare two arrays to define coordinators for 2 points
4. Plot graph for those mentioned points using matplot library
5. Stop the program
PROGRAM:
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 6])
ypoints = np.array([0, 250])
plt.plot(xpoints, ypoints)
plt.show()
OUTPUT:
8.D) SCIPY
AIM:
To write a python program to return the specified unit in seconds (eg. Hour returns
3600.0) using scipy library.
ALGORITHM:
1. Start the program
2. Import scipy from python standard library
3. Print specified units like minute, hour, day, etc in seconds using scipy
4. Stop the program
PROGRAM:
from scipy import constants
print('1 minute=',constants.minute,'seconds')
print('1 hour=',constants.hour,'seconds')
print('1 day=',constants.day,'seconds')
print('1 week=',constants.week,'seconds')
print('1 year=',constants.year,'seconds')
print('1 Julian year=',constants.Julian_year,'seconds')
OUTPUT:
('1 minute=', 60.0, 'seconds')
('1 hour=', 3600.0, 'seconds')
('1 day=', 86400.0, 'seconds')
('1 week=', 604800.0, 'seconds')
('1 year=', 31536000.0, 'seconds')
('1 Julian year=', 31557600.0, 'seconds')
AIM:
To write a python program to copy from one file to another.
ALGORITHM:
1. Start the program
2. Import copyfile from python standard libraries
3. Read source and destination file name
4. Copy data from source file to destination file and print ‘file copied successfully’
5. Stop the program
PROGRAM:
copyfile(sourcefile, destinationfile)
c=open(destinationfile, "r")
print(c.read())
c.close()
print()
print()
OUTPUT:
Data.txt
A file is a collection of data stored on a secondary storage device like hard disk. They can
be easily retrieved when required. Python supports two types of files. They are Text files &
Binary files.
ALGORITHM:
PROGRAM:
OUTPUT:
AIM:
Data.txt
A file is a collection of data stored on a secondary storage device like hard disk. They can
be easily retrieved when required. Python supports two types of files. They are Text files &
Binary files.
ALGORITHM:
PROGRAM:
def longest_word(filename):
with open(filename, 'r') as infile: words =
infile.read().split()
max_len = len(max(words, key=len))
return [word for word in words if len(word)==max_len]
print(longest_word('F:\Data.txt'))
OUTPUT:
['collection']
AIM:
To write a python program to handle divide by zero error using exception handling.
ALGORITHM:
1. Start the program
2. Read the values for n,d and c
3. Calculate Quotient=n/(d-c) in try block
4. If zeroDivisionError arise print Division by Zero
5. Stop the program
PROGRAM:
OUTPUT:
Enter the value of n:8
Enter the value of d:4
Enter the value of c:4
Division by Zero!
ALGORITHM:
1. Start the program
2. Read year of birth from user
3. Calculate age by subtracting year of birth from current year
4. If Age is less than or equal to 18 print ‘You are eligible to vote’. Otherwise print ‘You
are not eligible to vote’
5. Stop the program
PROGRAM:
import datetime
Year_of_birth = int(input("In which year you took birth:- "))
current_year = datetime.datetime.now().year
Current_age = current_year-Year_of_birth
print("Your current age is ",Current_age)
if(Current_age<=18):
print("You are not eligible to vote")
else:
print("You are eligible to vote")
OUTPUT:
In which year you took birth:- 2004
('Your current age is ', 18)
You are not eligible to vote
In which year you took birth:- 1994
('Your current age is ', 28)
You are eligible to vote
AIM:
To write a python program to perform student mark range validation
ALGORITHM:
PROGRAM:
Mark = int(input("Enter the Mark: "))
if Mark < 0 or Mark > 100:
print("The value is out of range, try again.")
else:
print("The Mark is in the range")
OUTPUT:
Enter the Mark: 123
The value is out of range, try again.
AIM:
To write a python program to create bouncing ball game activity using pygame
PROGRAM:
import pygame
pygame.init()
window_w = 800
window_h = 600
white = (255, 255, 255)
black = (0, 0, 0)
FPS = 120
window = pygame.display.set_mode((window_w, window_h))
pygame.display.set_caption("Game: ")
clock = pygame.time.Clock()
def game_loop():
block_size = 20
velocity = [1, 1]
pos_x = window_w/2
pos_y = window_h/2
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pos_x += velocity[0]
pos_y += velocity[1]
if pos_x + block_size > window_w or pos_x < 0:
velocity[0] = -velocity[0]
if pos_y + block_size > window_h or pos_y < 0:
velocity[1] = -velocity[1]
# DRAW
window.fill(white)
pygame.draw.rect(window, black, [pos_x, pos_y, block_size, block_size])
pygame.display.update()
clock.tick(FPS)
game_loop()
OUTPUT: