PSPP Lab Record Print-23-24 Odd
PSPP Lab Record Print-23-24 Odd
Name :
Register Number :
Degree / Branch :
Year / Semester :
Academic Year :
Reg. No:
BONAFIDE CERTIFICATE
This is to certify that this bonafide record of work was done by the candidate
Mr/Ms of
Page
Ex.No Date Title of the Experiment Marks Sign
No.
CYCLE - I
a. Electricity Billing
b. Retail shop billing
c. Program to find the sum of sine series
d. Weight of the steel bar
e. Computing Electrical Current in Three Phase AC
Circuit
PROGRAM:
units = int(input(" Please enter Number of Units you Consumed : "))
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
print("\nElectricity Bill = %.2f" %total)
OUTPUT:
Please enter Number of Units you Consumed: 120
Electricity Bill = 442.70
1b.Retail shop billing
PROGRAM:
n=int(input("Enter the number of items purchased"))
dict1={}
amount=0
for i in range(0,n):
key1=raw_input("Enter the product")
val=int(input("Enter the price of the product"))
qty=int(input("Enter the quantity of the product purchased"))
dict1[i]=val*qty
amount=amount+dict1[i]
print("The total amount is",amount)
OUTPUT:
Enter the number of items purchased2
Enter the productsoap
Enter the price of the product35
Enter the quantity of the product purchased2
Enter the productpaste
Enter the price of the product50
Enter the quantity of the product purchased1
('The total amount is', 120)
1c. Program to find the sum of sine series
PROGRAM:
import math
def sin(x,n):
sine = 0
for i in range(n):
sign = (-1)**i
pi=22/7
y=x*(pi/180)
sine = sine + ((y**(2.0*i+1))/math.factorial(2*i+1))*sign
return sine
x=int(input("Enter the value of x in degrees:"))
n=int(input("Enter the number of terms:"))
print(round(sin(x,n),2))
OUTPUT:
Enter the value of x in degrees:30
Enter the number of terms:10
0.5
1d. Weight of the steel bar
PROGRAM:
length=float(input("Enter the length of the steel"))
diameter=float(input("Enter the diameter of the steel"))
weight=diameter**2*length/162
print("The weight of the steel=",weight,"kg/m")
OUTPUT:
Enter the length of the steel1
Enter the diameter of the steel8
('The weight of the steel=', 0.3950617283950617, 'kg/m')
1e. Computing Electrical Current in Three Phase AC Circuit
PROGRAM:
from math import sqrt
V=int(input("Enter the line voltage"))
pf=1
P=int(input("Enter the power of current"))
I=P/(sqrt(3)*V*pf)
print("The three phase current received is ",I)
OUTPUT:
Enter the line voltage440
Enter the power of current746
('The three phase current received is ', 0.9788711382169565)
2a.Python program for exchange the values of two variables
PROGRAM:
x =10
y =50
temp =x
x =y
y =temp
print("Value of x:", x)
print("Value of y:", y)
OUTPUT:
Value of x:50
Value of y:10
2b. circulate the values of n variables
PROGRAM:
no_of_terms = int(input("Enter number of values : "))
list1 = []
for val in range(0,no_of_terms,1):
ele = int(input("Enter integer : "))
list1.append(ele)
print("Circulating the elements of list ", list1)
for val in range(0,no_of_terms,1):
ele = list1.pop(0)
list1.append(ele)
print(list1)
OUTPUT:
Enter number of values : 5
Enter integer : 1
Enter integer : 2
Enter integer : 3
Enter integer : 4
Enter integer : 5
('Circulating the elements of list ', [1, 2, 3, 4, 5])
[2, 3, 4, 5, 1]
[3, 4, 5, 1, 2]
[4, 5, 1, 2, 3]
[5, 1, 2, 3, 4]
[1, 2, 3, 4, 5]
2c. distance between two points
PROGRAM
x1=int(input("enter x1 : "))
x2=int(input("enter x2 : "))
y1=int(input("enter y1 : "))
y2=int(input("enter y2 : "))
result= ((((x2 - x1 )**2) + ((y2-y1)**2) )**0.5)
print("distance between",(x1,x2),"and",(y1,y2),"is : ",result)
OUTPUT:
enter x1 : 2
enter x2 : 4
enter y1 : 3
enter y2 : 6
distance between (2,4) and (3,6) is 3.605551275463989
3a. Number series
PROGRAM:
n=int(input("Enter a number: "))
a=[]
for i in range(1,n+1):
print(i,sep=' ',end=' ')
if(i<n):
print('+',sep=' ',end=' ')
a.append(i)
print('=',sum(a))
OUTPUT:
Enter a number: 4
1 + 2 + 3 + 4 = 10
3b. Number Patterns
PROGRAM:
rows=6
for i in range(rows):
for j in range(i):
print(i)
print('')
OUTPUT:
1
22
333
4444
55555
3c. pyramid pattern
PROGRAM:
def pypart(n):
myList =[]
for i in range(1,n+1):
myList.append("*"*i)
print("\n".join(myList))
# Driver Code
n =5
pypart(n)
OUTPUT:
*
**
***
****
*****
4a. Items present in a library
PROGRAM:
library =['Books','Newspaper','Periodicals','Manuscripts','Maps','Prints','Documents','Ebooks']
print('Library: ',library)
print('first element: ',library[0])
print('fourth element: ',library[3])
print('Items in Library from 0 to 4 index: ',library[0: 5])
library.append('Audiobooks')
print('Library list after append(): ',library)
print('3rd or -7th element: ',library[-7])
print('index of \'Newspaper\': ',library.index('Newspaper'))
library.sort()
print('after sorting: ', library);
print('Popped elements is: ',library.pop())
print('after pop(): ', library);
library.remove('Maps')
print('after removing \'Maps\': ',library)
library.insert(2, 'CDs')
print('after insert: ', library)
print(' Number of Elements in Library list : ',len(library))
OUTPUT:
('Library: ', ['Books', 'Newspaper', 'Periodicals', 'Manuscripts', 'Maps', 'Prints', 'Documents',
'Ebooks'])
('first element: ', 'Books')
('fourth element: ', 'Manuscripts')
('Items in Library from 0 to 4 index: ', ['Books', 'Newspaper', 'Periodicals', 'Manuscripts', 'Maps'])
('Library list after append(): ', ['Books', 'Newspaper', 'Periodicals', 'Manuscripts', 'Maps', 'Prints',
'Documents', 'Ebooks', 'Audiobooks'])
('3rd or -7th element: ', 'Periodicals')
("index of 'Newspaper': ", 1)
('after sorting: ', ['Audiobooks', 'Books', 'Documents', 'Ebooks', 'Manuscripts', 'Maps', 'Newspaper',
'Periodicals', 'Prints'])
('Popped elements is: ', 'Prints')
('after pop(): ', ['Audiobooks', 'Books', 'Documents', 'Ebooks', 'Manuscripts', 'Maps', 'Newspaper',
'Periodicals'])
("after removing 'Maps': ", ['Audiobooks', 'Books', 'Documents', 'Ebooks', 'Manuscripts',
'Newspaper', 'Periodicals'])
('after insert: ', ['Audiobooks', 'Books', 'CDs', 'Documents', 'Ebooks', 'Manuscripts', 'Newspaper',
'Periodicals'])
(' Number of Elements in Library list : ', 8)
4b. Components of a car
PROGRAM:
carcomp=('Engine', 'Transmission', 'Battery', 'Alternator', 'Radiator', 'Front Axle', 'Front Steering
and Suspension', 'Brakes', 'Fuel Tank', 'Rear Suspension', 'Rear Axle')
print("The components of cars are")
print(carcomp)
print("The carcomp tuple has",len(carcomp),"elements")
print("The index of Fuel Tank is",carcomp.index('Fuel Tank'))
print("The first five elements are")
print(carcomp[0:5:1])
print("Does Brakes is in carcomp",'Brakes' in carcomp)
OUTPUT:
The components of cars are
('Engine', 'Transmission', 'Battery', 'Alternator', 'Radiator', 'Front Axle', 'Front Steering and
Suspension', 'Brakes', 'Fuel Tank', 'Rear Suspension', 'Rear Axle')
('The carcomp tuple has', 11, 'elements')
('The index of Fuel Tank is', 8)
The first five elements are
('Engine', 'Transmission', 'Battery', 'Alternator', 'Radiator')
('Does Brakes is in carcomp', True)
5a. Operations using language
PROGRAM:
wordsdet={'attribute':'a quality or characteristic that someone or something has', 'bowled':'to roll a
ball along a smooth surface during a game of bowls or bowling','person': 'a human being',
'marathon': 'a running race that is about 26 miles', 'resist': 'to remain strong against the
force', 'run': 'to move with haste; act quickly'}
print(wordsdet.keys())
word=raw_input("Enter the words for which meaning is sought")
print(wordsdet[word])
OUTPUT:
['run', 'attribute', 'resist', 'person', 'bowled', 'marathon']
Enter the words for which meaning is sought
attribute
a quality or characteristic that someone or something has
5b. Components Of Automobile
PROGRAM:
Components={'Chassis':' frame, suspension system, axles, wheel',' Engine':' spark-ignition engine,
compression ignition engine',' Transmission System':' clutch, gearbox, propeller shaft, differential
and axle, live axle','Body':'Steering system and Braking system'}
print("The main components of an automobile are ")
print(Components.keys())
set1=set(Components.keys())
print("\n Detailed description about components\n")
for i in set1:
print(i)
print(Components.get(i))
print("\n")
OUTPUT:
The main components of an automobile are
['Body', ' Engine', ' Transmission System', 'Chassis']
Detailed description about components
Body
Steering system and Braking system
Engine
spark-ignition engine, compression ignition engine
Transmission System
clutch, gearbox, propeller shaft, differential and axle, live axle
Chassis
frame, suspension system, axles, wheel
5c. Elements of a civil structure
PROGRAM
elements={'line','surface','volume'}
line={'Rod' ,'Beam', 'Pillar', 'Post' , 'Struts', 'Ties'}
surface={'membrane', 'shell', 'shear_panel'}
volume={'Axial', 'shear','bending_loads'}
print("The basic elements of civil structure are")
print(elements);print("\n")
print("The line elements include")
print(line);print("\n")
print("The surface elements include")
print(surface);print("\n")
print("The volume elements include")
print(volume);print("\n")
print("In whole a civil structure needs the following")
print(line|surface|volume);print("\n")
line.remove('Ties')
print("After applying remove()",line);print("\n")
line.discard('Struts')
print("After applying discard()",line);print("\n")
line.pop()
print("After applying pop()",line);print("\n")
OUTPUT:
The basic elements of civil structure are
set(['volume', 'line', 'surface'])
The line elements include
set(['Pillar', 'Struts', 'Rod', 'Beam', 'Ties', 'Post'])
The surface elements include
set(['shear_panel', 'shell', 'membrane'])
The volume elements include
set(['bending_loads', 'Axial', 'shear'])
In whole a civil structure needs the following
set(['shear_panel', 'Pillar', 'Struts', 'Rod', 'bending_loads', 'Beam', 'Axial', 'shell', 'membrane', 'Ties',
'Post', 'shear'])
('After applying remove()', set(['Pillar', 'Struts', 'Rod', 'Beam', 'Post']))
('After applying discard()', set(['Pillar', 'Rod', 'Beam', 'Post']))
('After applying pop()', set(['Rod', 'Beam', 'Post']))
6a.Factorial of a number
PROGRAM:
def factorial(num):#function definition
fact=1
for i in range(1, num+1):#for loop for finding factorial
fact=fact*i
return fact #return factorial
number=int(input("Please enter any number to find factorial: "))
result=factorial(number)#function call and assign the value to variable result
print("The factorial of %d = %d"%(number,result))
OUTPUT:
Please enter any number to find factorial: 5
The factorial of 5 = 120
6b. largest number in a list
PROGRAM:
list1 =[]
num =int(input("Enter number of elements in list: "))
for i in range(1, num +1):
ele =int(input("Enter elements: "))
list1.append(ele)
print("Largest element is:", max(list1))
OUTPUT:
Enter number of elements in list: 4
Enter elements: 12
Enter elements: 19
Enter elements: 1
Enter elements: 99
Largest element is: 99
6c.Area of shape
PROGRAM:
choice=int(input("Enter the shape 1. Rectangle 2. Square 3. Triangle"))
if(choice==1):
l=float(input("enter the length of rectangle"))
b=float(input("enter the breath of rectangle"))
a=l*b
print(a)
elif(choice==2):
side = 6
Area = side*side
print("Area of the square="+str(Area))
elif(choice==3):
a = float(input('Enter the length of first side: '))
b = float(input('Enter the length of second side: '))
c = float(input('Enter the length of third side: '))
s = (a + b + c) / 2
Area = (s*(s-a)*(s-b)*(s-c))** 0.5
print('The area of the triangle is %0.2f' %Area)
else:
print("Undefined shape")
OUTPUT:
Enter the shape 1. Rectangle 2. Square 3. Triangle
1
enter the length of rectangle3
enter the breath of rectangle4
12.0
Enter the shape 1. Rectangle 2. Square 3. Triangle
2
Area of the square=36
Enter the shape 1. Rectangle 2. Square 3. Triangle
3
Enter the length of first side: 4
Enter the length of second side: 5
Enter the length of third side: 6
The area of the triangle is 9.92
Enter the shape 1. Rectangle 2. Square 3. Triangle
4
Undefined shape
7a. Reverse a string
PROGRAM:
def reverse(str):
string = " "
for i in str:
string = i + string
return string
str = "PythonGuides"
print("The original string is:",str)
print("The reverse string is:", reverse(str))
OUTPUT:
('The original string is:', 'PythonGuides')
('The reverse string is:', 'sediuGnohtyP ')
7b. palindrome
PROGRAM:
my_str = input("Enter a string: ")
my_str = my_str.casefold()
rev_str = reversed(my_str)
if list(my_str) == list(rev_str):
print("It is palindrome")
else:
print("It is not palindrome")
OUTPUT:
Enter the string
madam
The string is a palindrome.
7c. character count
PROGRAM:
string = "The best of both worlds";
count = 0;
#Counts each character except space.
for i in range(0, len(string)):
if(string[i] != ' '):
count = count + 1;
#Displays the total number of characters present in the given string.
print("Total number of characters in a string: " + str(count));
OUTPUT:
Total number of characters in a string: 19
7d. replacing characters
PROGRAM:
a_string = "aba"
a_string = a_string. replace("a", "b") #Replace in a_string.
print(a_string)
OUTPUT:
bbb
8a.pandas
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
Equals:
0 False
1 False
2 False
3 False
Greater than:
0 True
1 True
2 True
3 True
Less than:
0 False
1 False
2 False
3 False
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
8c. matplotlib library
PROGRAM:
OUTPUT:
8d. scipy library
PROGRAM:
print(constants.minute)
print(constants.hour)
print(constants.day)
print(constants.week)
print(constants.year)
print(constants.Julian_year)
OUTPUT:
60.0
3600.0
86400.0
604800.0
31536000.0
31557600.0
9a. copy from one file to another
PROGRAM:
with open("test.txt") as f:
with open("out.txt", "w") as f1:
for line in f:
f1.write(line)
OUTPUT:
Contents of file(test.txt):
Hello world
Output(out.text):
Hello world
9b. word count
PROGRAM:
fname = input("Enter file name: ")
num_words = 0
with open(fname, 'r') as f:
for line in f:
words = line.split()
num_words += len(words)
print("Number of words:")
print(num_words)
OUTPUT:
Contents of file:
Hello world
Output:
Enter file name: data1.txt
Number of words:
2
9c. longest word
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('test.txt'))
OUTPUT:
Contain of text.txt
What is Python language?
Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
Its design philosophy emphasizes code readability, and its syntax allows programmers to express
concepts in fewer lines of code than possible in languages such as C++ or Java.
Python supports multiple programming paradigms, including object-oriented, imperative and
functional programming or procedural styles. It features a dynamic type system and automatic
memory management and has a large and comprehensive standard library. The best way we learn
anything is by practice and exercise questions.
Output:
['general-purpose,', 'object-oriented,']
10a. divide by zero error
PROGRAM:
n=int(input("Enter the value of n:"))
d=int(input("Enter the value of d:"))
c=int(input("Enter the value of c:"))
try:
q=n/(d-c)
print("Quotient:",q)
except ZeroDivisionError:
print("Division by Zero!")
OUTPUT:
Enter the value of n:10
Enter the value of d:5
Enter the value of c:5
Division by Zero!
10b. voter’s age validity
PROGRAM:
def main():
try:
age=int(input("Enter your age"))
if age>18:
print("Eligible to vote")
else:
print("Not eligible to vote")
except ValueError as err:
print("age must be a valid number",err)
except:
print("An Error occured")
finally:
print("Thank you")
main()
OUTPUT:
Enter your age21
Eligible to vote
Thank you
10c. student mark range validation
PROGRAM:
Marks = int(input("Enter Marks: "))
try:
if(Marks < 1 or Marks>100):
raise ValueError("Mark can't be less than 1 or greater than 100")
else:
print("Mark scored is",Marks)
except ValueError as e:
print ("Received error", e)
OUTPUT:
Enter Marks: 45
('Mark scored is', 45)
Enter Marks: -5
('Received error', ValueError("Mark can't be less than 1",))
3.Click
171kB/s
RESULT:
Thus the exploring pygame was successfully installed.
12.Pygame like bouncing ball
PROGRAM:
import sys
import pygame
pygame.init()
size = width, height = 420, 340
speed = [1,1]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load('F:\\AHB\\Haseena\\ball2.jpg') ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width: speed[0] =-speed[0]
if ballrect.top < 0 or ballrect.bottom >height: speed[1] =-speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
OUTPUT: