PSPP - Record Mech
PSPP - Record Mech
NAME : …………………………………………….……
REG NO : ………………………………………………….
SUBJECT : …………………………………………….……
COURSE : …………………………………………….……
SEMESTER : …………………………………………….……
BATCH : …………………………………………….…….
KGISL Institute Of Technology - KITE
Coimbatore – 641 035.
NAME :
CLASS :
UNIVERSITY REG NO :
1 DEVELOPING FLOWCHART
AIM
To write a Python program to calculate electricity bill.
ALGORITHM
Step 4: If units to charge is in range 100 - 200 the charges is equal to product of (unit of charge –
100) and 1.5 + fixed charge
Step 5: If units to charge is in range 100 – 200 the charges is equal to product of (unit to charge –
100) and 1.5 + fixed charge
Step 6: If units to charge is in range 201 – 500 the charges is equal to sum of (100*1.5) and
product of (unit to charge – 100) with 4 and fixed charge
Step 7: Display the bill amount which is equal to sum of fixed charge and charge for range (100
- 500)
Step 8: Stop the procedure
FLOWCHART
START
Consumed=current reading
– previous reading
Cost=0
If
consumed<=10 Fixed charges=0
0
Cost=(consumed -
If 100)*1.5
consumed>100
and Fixed charges=20
consumed<=20
If Cost=(100*2)+((consumed
consumed>200 -200)*3)
and
consumed<=50 Fixed charges=30
If Cost=(100*3.5)+(300*4.6)
+((consumed-500)*6.6)
consumed>500
Fixed charges=50
DISPLAY
consumed,cost,fixed
Bill_amount = cost+fixed
charges
DISPLAY
bill_amount
STOP
PROGRAM
eb_no=int(input("Enter the TNEB Number:"))
consumed=current_reading-last_reading
print("-------SlabCalculations--------- ")
fixed=0
slab1=0
print("Fixed charges",fixed)
bill=slab1+fixed
fixed=20
slab1=(consumed-100)*1.50
print("Fixed charges",fixed)
bill=slab1+fixed
fixed=30
slab1=0
slab2=100*2
slab3=(consumed-200)*3
print("Fixed charges",fixed)
bill=slab1+slab2+slab3+fixed
if (consumed>500):
fixed=50
slab1=0
slab2=100*3.5
slab3=300*4.6
slab4=(consumed-500)*6.60
print("Fixed charges",fixed)
bill=slab1+slab2+slab3+slab4+fixed
print(" ")
print("EB Number:",eb_no)
print("Units consumed",consumed)
print(" ")
OUTPUT
RESULT
The above program for calculating electricity bill is executed and the output is verified
successfully.
Ex no: RETAIL STORE BILLING
Date:
AIM
To write a Python program to calculate retail store bill.
ALGORITHM
Step1: Start
Step3: Set bill_amount <- 0 and create 3 empty lists Items, Qty and Price.
Step4: Get the choice from user and get the item name, price and quantity and append to their
respective lists.
Step5: To print the bill, print the customer name, mobile number and date. Then print the
product, quantity, price and bill of the respective item. Finally calculate total bill by adding
all the bill of the product chosen by user.
Step6: Stop
FLOWCHART
START
READ name ,
mobilenum and date
Bill_amount=0
Item=[ ]
Qty=[ ] Price=[ ]
READ op
If op==1 Item.apppend(Fruitname)
READ product
Price.append(Fruitprice)
name, quantity
Qty.append(FruitQty)
,price
If op==5
Item.apppend(Oilname)
READ product
Price.append(Oilprice)
name, quantity
,price Qty.append(OilQty)
IC in
range
(len(item
PRINT
Item[IC],Qty[IC],Price[I
C],Price[IC]*Qty[IC]
Bill_amount=Price[IC]
*Qty[IC]
PRINT
Bill_amount
STOP
PROGRAM
print("\t\tWelcome to \n ***Kannan Departmental Store***")
print(" ")
bill_amount=0
Items=[]
Qty=[] Price=[]
print("***********Menu*************")
print('''
1. Fruits
2. Vegetables
3. Cosmetics
4. Grains
5. Oil
6. Exit
''')
while op in [1,2,3,4,5]:
if op==1:
Items.append(FruitName)
Price.append(FruitPrice)
if op==2:
Items.append(VegetableName)
Price.append(VegetablePrice)
Qty.append(VegetableQty)
if op==3:
Items.append(CosmeticName)
Price.append(CosmeticPrice)
Qty.append(CosmeticQty)
if op==4:
Items.append(GrainsName)
Price.append(GrainsPrice)
Qty.append(GrainsQty)
if op==5:
Items.append(OilName)
Price.append(OilPrice)
OilQty=int(input("Enter the Quantity(Litre) : "))
Qty.append(OilQty)
print("Do you have another item ,If yes print the options or else enter 6")
print('''
1. Fruits 2. Vegetables
3. Cosmetics 4. Grains
5. Oil 6. Exit
''')
print("\n*************Bill************")
print(" ")
print("Date:%s"%date)
print(" ")
print("Product\tQuantity\tPrice\tBill")
for IC in range(len(Items)):
bill_amount+=(Price[IC]*Qty[IC])
print(" ")
print(" ")
AIM
To write an python program to calculate the sine series of a given number and terms.
ALGORITHM
Step1: Start
Step3: Define another function to find sine value of the given number
Step4: Get two variables for number of terms and value for sine variable
Step9: Stop
FLOWCHART
START
START
Factorial(n)
Factorial(n)
Sin(n)
Fact=1
Pi=3.14
i in
range(1,n+ Read x,n
1)
Print x
Fact*=1
Print sin(x,n)
Return Fact
END
STOP
START
Sin(x,n)
Sine=0
j in
range(0,
n)
Sign=(-1)**j
Sine=Sine+((X**(2.0*j+1))/factorial(2*j+1))*Sign
Return sine
STOP
PROGRAM
#Factorial of Given Number
def factorial(n):
res = 1
res *= i
return res
#sine function
def sin(x,n):
sine=0
for i in range(0,n):
sign=(-1)**i
sine=sine+((x**(2.0*i+1))/factorial(2*i+1))*sign
return sine
#Pi Value
pi=22/7
x*=(pi/180)
RESULT
The above program for finding sine series is executed and the output is verified successfully.
Ex no.: WEIGHT OF A STEEL BAR
Date:
AIM
To write a Python program to find the total weight of the given steel bar.
ALGORITHM
Step1: Start
Step4: Calculate weight of steel bar per meter by dividing Dsquare with 162
Step7: Stop
FLOWCHART
START
Read SteelDiameter,
SteelLen
Dsquare=
SteelDiameter*SteelDiameter
Weight_of_steel_per_meter
= Dsquare/162
Total_weight_of_steel=( Ds
quare*SteelLen)/162
PRINT
Total_weight_of_steel
STOP
PROGRAM
SteelDiameter = int(input("Enter The Length of the Steel Diameter(mm):"))
e = "{:.2f}".format(WeightofSteelPerMeter)
f = "{:.2f}".format(TotalWeightofSteel)
RESULT
The above program for finding the total weight of the given steel bar is executed and output
is verified successfully.
COMPUTE ELECTRICAL CURRENT IN
THREEPHASE AC CIRCUIT
Ex.no:
Date:
AIM
To write a Python program to compute electrical current in three phase AC circuit.
ALGORITHM
Step1: Start
Step6: Assign a variable root3 and call the function newton method and return root3 value
from the function.
Step8: Display the calculated electric current in three phase electric AC current
Step9: Stop
FLOWCHART
START
Newton_method(num,nu
m_iters=100)
READ a
i in range
(num_iter
Iternum=num
Num=0.5*(num+a/num)
Num==
Break
iternum
Return num
STOP
START
START
Newton_method(num
,num_iters=100)
Threephase(voltag
e,current,root3)
Threephase(volta
ge,current,root3) Kva=voltage*current
*root3
Read
voltage,current
Return kva
Print
voltage,current
STOP
Root3=newton_method
(3)
Print threephase
(voltage,current,r
oot3)
STOP
PROGRAM
def newton_method(number, number_iters = 100):
a = float(number)
for i in range(number_iters):
iternumber=number
if number==iternumber:
break
return number
def threephase(voltage,current,root3):
kva=voltage*current*root3
return kva
root3=newton_method(3)
RESULT
The above program for computing electrical current in three phase AC circuit is executed and
output is verified successfully.
Ex no: EXCHANGE THE VALUE OF TWO VARIABLES
Date:
AIM
To write a python program to exchange the value of given variables.
ALGORITHM
Step 1: Start.
i. Temporary variable
ii. XOR operator
iii. Swap – function
iv. Addition and Subtraction
Step 4: Initialize a temporary variable and swap values.
Step 8: Stop.
PROGRAM
print("Enter two values to swap")
print("*"*40)
temp = V1
V1 = V2
V2 = temp
print("*"*40)
V1 = V1 ^ V2
V2 = V1 ^ V2
V1 = V1 ^ V2
print("*"*40)
def swap_func():
global V1, V2
V1, V2 = V2, V1
swap_func()
print("*"*40)
print("Before Swapping V1 is ",V1," V2 is ",V2)
V1 = V1 + V2
V2 = V1 - V2
V1 = V1 - V2
Read V1, V2
temp = V1
V1 = V2
V2 = temp
START
print V1, V2
swap_functio
V1 = V1^V2 n(V1,V2)
V2 = V1^V2
V1 = V1^V2
V1, V2 = V2,V1
print V1, V2
Return V1, V2
swap_function(V1,V2)
STOP
swap = swap_func(V1,V2)
V1 = swap[0]
V2 = swap[1]
print V1, V2
V1 = V1 + V2
V2 = V1 - V2
V1 = V1 – V2
OUTPUT
RESULT
The python program to exchange the value of given variables was executed and verified
successfully.
Ex No.: DISTANCE BETWEEN TWO POINTS
Date:
AIM
To write a python program to find distance between two points.
ALGORITHM
Step 1: Start.
Step 7: Stop.
PROGRAM
def newton_method(number):
x = float(number)
yn=number
for i in range(100):
yn1=yn
if yn==yn1:
break
return round(yn,2)
x1, y1 = pointA
x2, y2 = pointB
distx = x2 - x1
disty = y2 - y1
newton_method
Read x
i in range
(newton_method)
False
iternumberTrue
= number
False
return number
STOP
START START
newton_method distance_between(pointA,poin
tB)
(number, number_iters = 100)
distance_between(pointA,poin x1,y2=pointA
tB)
x2,y2=pointB
read
distx=x2-x1
pointA,pointB
disty=y2-y1
print root_2=newton_method(distx**2+disty**
distance_betwee 2)
n(pointA,pointB
return
round(root_2,2)
STOP
STOP
OUTPUT
RESULT
The above python program to find distance between two points was executed and verified
successfully.
Ex no.: CIRCULATE THE N VALUES
Date:
AIM
To write a python program to get an input from user and circulate N values.
ALGORITHM
Step 1: Start.
Step 4: Get values from the user and append it to the list.
Step 6: Pass the values from the user and print the values.
Step 7: Circulate the N values from the user and print the values.
Step 9: Stop.
FLOWCHART
START
Read n
Print lis1
Circulate (Nvalues)
Circulate (list1)
STOP
PROGRAM
def circulate(alist):
for i in range(len(alist)):
first=alist.pop(0) alist.append(first)
return alist
def GetNValues(n):
NValues=[]
for i in range(n):
NValues.append(Value)
return NValues
NValues=GetNValues(n)
circulate(NValues)
FLOWCHART
START
START
Nvalues = []
i in range (n)
False
i in range (n)
b = Nvalues[0]
Nvalues.pop(0)
True
Read a Nvalues.append(b)
Print N values
Nvalues.append(a)
STOP
Return N values
STOP
OUTPUT
RESULT
The python program to get an input from user and circulate N values was executed and
verified successfully.
Ex no.: NUMBER SERIES
Date:
AIM
To write a program to find the number series.
ALGORITHM
Step 1: Start the procedure.Step 2: Get number of the elements as input from the user.
Step 3: Choose anyone N series from the options.
Step 4: If the choice is 1, then use for loop and range function to find 1+2+3+……….+N.
Step 5: If the choice is 2 , then use for loop and range function to find
1^2+2^2+3^2+....+N^2.
Step 6: If the choice is 3,then use loop and range function to find
1+(1+2)+(1+2+3)+……N.
Step 7: Display the result.
Step 8: Stop the procedure.
PROGRAM:
N = int(input("Enter a number of a element:"))
choice = int(input("""
Number Series
sum = 0
if choice == 1:
for N in range(1,n+1)
sum +=N
if choice == 2:
for N in range(1,n+1)
sum +=N**2
if choice == 3:
for N in range(1,n+1)
sum +=N
RESULT
The above program for finding the number is executed and the output is verified
successfully.
Ex no: NUMBER PATTERN
Date:
AIM
To write a program to find the number pattern.
ALGORITHM
choice = int(input('''
Number Pattern
if choice == 1:
for n in range(1,n+1):
if n%2!=0:
print(n)
if choice == 2:
for n in range(1,n+1):
if n%2 == 0:
print(n)
OUTPUT
RESULT
The above program coding has been executed and the output is verified successfully.
Ex no: PYRAMID PATTERN
Date:
AIM
To write a program to find the pyramid pattern in python.
ALGORITHM
RESULT
The above program has been executed and the output is verified successfully.
Ex no.: LIBRARY MANEGMENT SYSTEM
Date:
AIM
To write a program for the library management system.
ALGORITHM
Step 1: START
Step 2: READ the choice in the list from the user as an input.
Step 3: Declare the list of options in library like Add Book, View Book, Issue book,
Step 7: Repeat step 4 for all the options selected by the user.
Step 9: STOP
PROGRAM
print("_"*50)
print("_"*50)
BooksCatelogue=["PSPP","Maths I","English","Physics","Chemistry"]
IssuedBook=[]
choice=int(input(('''
1.Add Book
2.Delete Book
4.Issue Book
5.Return Book
while choice:
if choice==1:
print("#"*20)
print("#"*20)
BooksCatelogue.append(getBookName)
if choice==2:
print("#"*20)
print("#"*20)
BooksCatelogue.remove(getBookName)
if choice==3:
print(" "*5,"#"*20)
print("#"*20)
print(sno,"-",book,"-",BooksCatelogue.count(book),"Available")
if choice==4:
print("#"*20)
print("#"*20)
IssuedBook.append(getBookName)
BooksCatelogue.remove(getBookName)
if choice==5:
print("#"*20)
print("#"*20)
BookID=BooksCatelogue.index(getBookName)
BooksCatelogue.pop(BookID)
print("_"*50)
print("_"*50)
choice=int(input('''
0.Exit
1. Add Book
2. Delete Book
4.Issue Book
5.Return Book
RESULT
The above program for the library management system is executed and output
verified successfully.
Ex no: CAR ENGINE COMPONENT ANALYZIER
Date:
AIM
To write the program to check the working condition of car engine components in
percentage.
ALGORITHM
Step 1: START
Step 7: STOP.
PROGRAM
# Car Engine Components Condition Analyzer print("#"*10,
'KT CAR Engine Analyzer Toolkit','#'*10,'\n')
EngineParts=['engine cylinder block ', 'combustion chamber', 'cylinder head', ' pistons', '
crankshft', 'camshaft', 'timing chain', ' valvetrain', 'valves', 'rocker arms', 'pushrods/lifters',
'fuel injectors', 'spark plugs']
RESULT
The above program for checking the working condition of car engine component in
percentage is executed and the output is verified successfully.
Ex no.: MATERIALS REQUIREMENT ANALYZER
Date:
AIM
To write the programme for the materials required to construct the building for the given
area.
ALGORITHM
Step 1: START
Step 2: READ the building area in sqft as input from the user.
(Cement=0.4, Sand = 1.2, Bricks = 11, Aggregates = 1.5, Steel bars = 4, Flooring Tiles =
0.07)
Step 7: Calculate the Materials requirement use formula
Step 9: STOP
PROGRAM
def BuildMatCalculation(AREA):
BUILDING_MATERIALS=['CEMENT BAGS', 'SANDS', 'BRICKS', 'AGGREGATES',
'STEEL BAR','FLOORING TILES']
MEASUREMENT_OF_BUILDING_MATERIALS=['50 KG BAGS','CUBIC
ft','nos','CUBIC ft','KG','LITTER']
Sqft_Calculation=[0.4,1.2,11,1.5,4,0.07]
print(f"{'NO':<9}{'MATERIALS':<18}{'QUANTITY':<12}{'MEASUREMENT':<9}")
print("-"*50)
for NO,MATERIALS,QUANTITY,MEASUREMENT in
zip(range(1,len(BUILDING_MATERIALS)),BUILDING_MATERIALS,
Sqft_Calculation,MEASUREMENT_OF_BUILDING_MATERIALS):
print(f"{NO:<9}{MATERIALS:<18}{round((QUANTITY*AREA),2):<12}
{MEASUREMENT:<9}")
print("-"*50)
RESULT
The above the programme for the materials required to construct the building for the given
area is executed and the verified successfully.
Ex no: COMPONENTS OF AUTOMOBILE
Date:
AIM
To write a program to check the genuine automobile components
ALGORITHM
Step1: START
Step3: Get the number of Automobile components you to Check and their HSN code.
Step4: Use input() function for how many components wants to check
Step6: Display the Genuine HSN code and non Genuine HSN code.
Step7:STOP
PROGRAM
print(" \tAutomobile Genuine Components Checker")
print("%"*50)
APPROVED_HSN={'HSN0029','HSN0045','HSN0043','HSN0076','HSN098'}
HSNCode=set({})
for GC in range(1,ComponentCount+1):
print("\n\tGenuined HSNCodes\n","-"*30)
print(sno,code)
print(sno,code)
OUTPUT
RESULT
The above program coding has been followed and the output has been verified successfully.
Ex no: ELEMENTS OF A CIVIL STRUCTURE
Date:
AIM
To write a program to find the elements of civil structure
ALGORITHM
Step1: START
Step8: Display the Elements in your building, Missing Elements, New Elements, Common
elements, Uncommon elements and All the Elements.
Step10: STOP
PROGRAM
print(" ### Building Structure Analyzer ### \n")
General_Elements={'Roof','Parapet','Lintels','Beams','Columns','Damp_Proof_Course'
,'Walls','Floor','Stairs','Plinth_Beam','Foundation','Plinth'}
def op(elements):
print(NO,'-',GE)
op(General_Elements)
Elements={}
if Element in Elements:
Elements[Element]+=1
else:
Elements[Element]=1
op(set(Elements.keys()))
op(General_Elements-set(Elements.keys()))
op(set(Elements.keys())-General_Elements)
print("\n --- Common Elements in Your Building & General Elements --- ")
op(set(Elements.keys())&General_Elements)
print("\n --- Not Common Elements in Your Building & General Elements ---")
op(set(Elements.keys())^General_Elements)
op(set(Elements.keys())|General_Elements)
OUTPUT
RESULT
The above program is executed and output is verified successfully.
Ex.no: FACTORIAL OF A NUMBER
Date:
AIM
To write a program to calculate factorial of a number.
ALGORITHM
Step 1: START
i = 1, fact = 1
Step 5: Calculate
fact = fact*I
Step 8: STOP
PROGRAM
#factorial
def factorial(num):
if num==1:
return num
else:
return num*factorial(num-1)
print(f"Factorial of '{num}'is",factorial(num))
OUTPUT
RESULT
The above program for calculating factorial of a number is executed and the output is verified
successfully.
Ex no.: LARGEST NUMBER IN A LIST
Date:
AIM
ALGORITHM
Step 1: START
Step 2: Create the list and get the elements from the user.
Step 5: Store and display the larget number from the sorted list.
Step 6: STOP
PROGRAM
def bubblesort(list):
print(alist)
indexes = range(len(alist))
print("inter", alist)
return alist
sorted_list=bubblesort(alist)
RESULT
The above program for finding largest number in a list is executed and the output is verified
successfully.
Ex no: AREA OF SHAPE
Date:
AIM
To write a program to calculate Area of shapes.
ALGORITHM
Step 1: START
Step 2: Display the option and get the input as option number from the user.
Step 3: Create a user defined function for calculating the area of the shape.
Step 4: Inside the function, calculate the area of shapes, Square = a*a
Rectangle = a*b
Circle = 3.14*(r*r)
Triangle = ½*(b*h)
Parallelogram = b*h
Rhombus = ½*(d1)*(d2)
Kite = ½*(d1)*(d2)
Step 6: STOP
PROGRAM
def square(x):
return x**2
def rectangle(l,w):
return l*w
def circle(r,pi=3.14):
return pi*(r**2)
def triangle(b,h):
return b*h*(1/2)
def parallelogram(b,h):
return b*h
def isosceles_trapezoid(a,b,h):
return (1/2)*(a+b)*h
def rhombus_kite(d1,d2):
return (1/2)*d1*d2
choice=int(input("""
1.square
2.rectangle
3.circle
4.triangle
5.parallelogram
6. isosceles trapezoid
7.rhombus
8.kite
if choice==1:
if choice==2:
if choice==3:
if choice==4:
if choice==5:
if choice==6:
if choice==7:
d1,d2=input("Enter the 'distance 1' and 'distance 2' value of rhombus : ").split()
if choice==8:
d1,d2=input("Enter the 'distance 1' and 'distance 2' value of kite : ").split()
RESULT
The above program for calculating area of the shape is executed and the output is verified
successfully.
Ex no.: CHECKING PALINDROME IN A STRING
Date:
AIM
To write a program check the give string is palindrome or not.
ALGORITHM
Step 1: Start
6.2: i = i – 1
Step 8: ELSE
Step 9: Stop
PROGRAM
string=input ("Enter the string : ")
rstring=string [::-1]
if string==rstring:
else:
RESULT
The above program has been executed and output has been verified successfully.
Ex no.: COUNTING CHARACTER IN A STRING
Date:
AIM
To write a program to find the character count of a string.
ALGORITHM
Step 1: start
Step3: Use Looping Statement to count the characters in the given String
Step 6: stop
PROGRAM
string=input("Enter the string : ")
charCount=0
charCount+=len(word)
RESULT
The above program has been executed and the output has been verified successfully.
Ex no.: REPLACING A CHARACTER IN A STRING
Date:
AIM
To write a program to replace a character in a string.
ALGORITHM
Step 1: Start
Step 8: Stop
PROGRAM
string=input("Enter the string : ")
stringlist=list(string)
if stringlist[idx]==charChange:
stringlist[idx]=repString
ReplacedString=" "
RESULT
The above program has been executed and the output has been verified successfully.
Ex no.: STUDENT MARK SYSTEM USING NUMPY AND PANDA
Date:
AIM
To write a Python program to print the student mark system using numpy and panda library.
ALGORITHM
INSTALLING PACKAGES
PROGRAM
import os
import pandas as pd
import numpy as np
import matplotlib
#code here
d={
'RollNumber':[1,2,3,4],
'StudentName':['kamal','vimal','vinoth','wahi'],
'Score':[64,68,61,86]}
df = pd.DataFrame(d)
#get grade by adding a column to the dataframe and apply np.where(), similar to a nested if
df_no_indices = df.to_string(index=False)
print(df_no_indices)
#print(df)
#Graphical Representation using Matplotlib
rollnumber=d['RollNumber']
names = d['StudentName']
values = d['Score']
#fig = plt.figure("YourWindowName")
fig.set_figheight(4)
fig.set_figwidth(10)
plt.subplot(131)
plt.bar(names, values)
OUTPUT
RESULT
The above program for printing student mark system using numpy and panda is executed and
the output is verified successfully.
Ex no.: LINEAR REGRESSION USING SCIPY
Date:
AIM
To write an python program to print linear regression using scipy library.
ALGORITHM
import numpy as np
import pandas as pd
x = np.random.random(10)
y = np.random.random(10)
df = pd.DataFrame({'x':x,'y':y})
print(df)
plt.suptitle('Linear Regression')
plt.legend()
plt.show()
OUTPUT
RESULT
The above program for printing linear regression using scipy is executed and the output is
verified successfully.
Ex no: COPY THE CONTENT FROM ONE FILE TO ANOTHER FILE
Date:
AIM
To Find Copy the Content from One File to another File of a Given Number and Terms
ALGORITHM
Step1: START
Step2: Open one file called file 1.txt in read mode.
Step3: Open another file 2. txt in write mode.
Step4: Read each line from the input file 1 and Copy into the output file 2
Step5: Read each line from the input file 2 and Copy into the output file 3
Step6: STOP
PROGRAM
of1=open('file1.txt','r')
of2=open('file2.txt','w+')
content=of1.read()
of2.write(content)
of1.close()
of2.close()
import shutil
shutil.copyfile('file2.txt','file3.txt')
RESULT
The Python Program is executed and output verified successfully.
Ex no.: WORD COUNT
Date:
AIM
To write a program to word count in a file.
ALGORITHM
Step1: START
Step4: For the Word in the file to Display the count of the word
Step5: For the Unique words in the file to Display the count of the word
Step6: STOP
PROGRAM
import re
words=re.findall('\w+', open('text1.txt').read().lower())
print(word)
uniquewords=set(words)
print(uniqueword)
RESULT
The above program is executed and output is verified successfully.
Ex no.: LONGEST WORD IN A TEXT FILE
Date:
AIM
To Write a Program for finding Longest word in a Text file
ALGORITHM
Step1: START
Step2: Import re
Step5: For Word in the file and Length of the word is to the file to Display the Word
Step6: STOP
PROGRAM
import re
words=re.findall('\w+', open('text1.txt').read().lower())
longword=words[0]
if len(word)>len(longword):
longword=word
RESULT:
The above program is executed and output has been verified successfully.
Ex no: DIVIDE BY ZERO ERROR
Date:
AIM
To write program to divide by zero error by exception handling.
ALGORITHM
Step1: START
try:
quotient=dividend/divisor
op=quotient
op=error
finally:
RESULT
The python program is executed and the output is verified.
Ex no: VOTERS AGE VALIDATION
Date:
AIM
To write a python program to check voter age validity.
ALGROTHM
Step1: START.
Step2: Get year and birth, current year and current age.
Step4: If current age is <=18 then print you are not eligible to vote
try :
fo=open('peoplelist.txt','r')
peoplelist=fo.readlines()
error=None
except IOError as e:
error=e
finally:
if not error:
name,age=people.split(' ')
if int(age)>=18:
else:
else:
print(error)
OUTPUT
RESULT
The python program is executed and the output is verified.
Ex no: STUDENTS MARK RANGE VALIDATION
Date:
AIM
To write a python program to perform students marks range validation.
ALGORITHM
Step 1:Create a text file as studentmarklist with student name, roll number and marks
Step 6:In finally block use if condition for check the error.
Step 7:If not error, Check the students marks and allocate the grade using For Loop. Else
try :
fo=open('studentmarklist.txt','r')
studentmarklist=fo.readlines()
error=None
except IOError as e:
error=e
finally:
if not error:
RollNumber,Name,MarksPercentage=tuple(re.findall('\w+',student))
if int(MarksPercentage)>70:
print(RollNumber," - 'pass'")
else:
print(RollNumber," - 'fail'")
else:
print(error)
OUTPUT
RESULT
The python program is executed and the output is verified.
Ex no: PYGAME TOOL BASICS
Date:
AIM
To write a program to create pygame using pygame library.
PROCEDURE
INSTALLING PACKAGES
1.Go to this link to install pygame www.pygame.org/download.html.
width = 500
height = 200
RED = (255, 0, 0)
BLACK = (0, 0, 0)
dir = {K_LEFT: (-5, 0), K_RIGHT: (5, 0), K_UP: (0, -5), K_DOWN: (0, 5)}
pygame.init()
running = True
OUTPUT
RESULT
The above program has been executed and output is verified successfully.
Ex no: BOUNCING BALL USING PYGAME
Date:
AIM
To write a program to bounce a ball using pygame library.
ALGORITHM
pygame.init()
'''logo = pygame.image.load("logo.png")
pygame.display.set_icon(logo)'''
pygame.display.set_caption("Bouncing Ball")
screen = pygame.display.set_mode(screen_size)
black = (0, 0, 0)
# Ball setup
ball = pygame.image.load("1.jpg")
ball_rect = ball.get_rect()
ball_speed = [1, 1]
# Game Loop
while True:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Ball update
ball_rect = ball_rect.move(ball_speed)
if ball_rect.left < 0 or ball_rect.right > screen_width:
ball_speed[0] = -ball_speed[0]
ball_speed[1] = -ball_speed[1]
# Screen update
screen.fill(black)
screen.blit(ball, ball_rect)
pygame.display.flip()
OUTPUT
RESULT
The above program has been executed and output is verified successfully