Emailing PYTHON LAB MANUAL (1 TO 50)
Emailing PYTHON LAB MANUAL (1 TO 50)
NAME : …………………………………………….…….
REG NO : …………………………………………………..
COURSE : …………………………………………….…….
SEMESTER : …………………………………………….…….
BATCH : …………………………………………….……..
SHREENIVASA ENGINEERING COLLEGE
(Approved by AICTE and Affiliated to Anna University)
B.Pallipatti, Bommidi, Pappireddipatti (Tk), Dharmapuri Dt, Tamilnadu-635 301
NAME :
CLASS :
1 DEVELOPING FLOWCHART
AIM
To write a Python program to calculate electricity bill.
ALGORITHM
Step1: START
Step2: Read TNEB consumer number, last bill meter reading and current bill meter reading
as input.
PRINT (slab3)
PRINT (fixed)
bill <- slab1+slab2+slab3+fixed IF
(consumed > 500) then
fixed <- 50
slab1 <- 0 PRINT
(slab1) slab2 <-
1
100*3.5 PRINT
(slab2) slab3 <-
300*4.60 PRINT
(slab3)
slab4 <- (consumed-500)*6.60
PRINT (slab4)
PRINT (fixed)
bill <- slab1+slab2+slab3+slab4+fixed Step5:
Store the value of bill and display it.
Step6: Stop
PSEUDOCODE
TASK: Calculate electricity bill
BEGIN
READ TNEB consumer number, last bill meter reading and current bill meter reading
COMPUTE consumed units
Consumed=cur_reading-last_reading
END consumed units
IF (consumed <= 100 AND consumed>=0) THEN
fixed = 0 slab1 = 0 PRINT
(fixed) bill = slab1+fixed
END IF
=slab1+fixed
END IF
IF (consumed <= 500 AND consumed >=201) THEN
fixed = 20 slab1 =
0 PRINT (slab1)
slab2 = 100*2 PRINT
2
(slab2) slab3 = (consumed-
200)*3.0
PRINT (slab3)
PRINT (fixed) bill =
slab1+slab2+slab3+fixed
END IF
IF (consumed > 500) THEN
fixed = 50 slab1 = 0
PRINT (slab1) slab2 =
100*3.5 PRINT (slab2)
slab3 = 300*4.60 PRINT
(slab3) slab4 = (consumed-
500)*6.60
PRINT (slab4)
PRINT (fixed)
3
END IF
bill = slab1+slab2+slab3+slab4+fixed
END TASK
FLOWCHART
START
Cost=0
If consumed<=100
Fixed charges=0
Cost=(consumed -
If consumed>100 and 100)*1.5
consumed<=200
Fixed charges=20
If
Cost=(100*2)+((consumed
consumed>200
-200)*3)
and
consumed<=500 Fixed charges=30
4
PRINT bill
END
5
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
6
PROGRAM
eb_no=int(input("Enter the TNEB Number:"))
print("-------SlabCalculations-------")
1-100 charge:",slab1)
print("Fixed charges",fixed)
bill=slab1+fixed
fixed=20 slab1=(consumed-
charge:",slab1) print("Fixed
charges",fixed) bill=slab1+fixed
slab3=(consumed-200)*3
print("Fixed charges",fixed)
bill=slab1+slab2+slab3+fixed if
(consumed>500):
charge:",slab1) slab2=100*3.5
charge:",slab3) slab4=(consumed-
charges",fixed)
bill=slab1+slab2+slab3+slab4+fixed
print("---------------------------------")
consumed",consumed)
8
OUTPUT
9
RESULT
Thus the program for calculating electricity bill is executed and output is verified
successfully.
10
EX.NO: 1 B
DATE: RETAIL STORE BILLING
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’s 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
PSEUDOCODE
TASK: To calculate retail store bill
BEGIN
SET bill_amount=0
PRINT bill_amount
11
FLOWCHART
START
READ name
,mobilenum and date
Bill_amount=0
Item=[ ]
Qty=[ ] Price=[ ]
PRINT 1.Fruits
2.Vegetables 3.Cosmetics
4.Grains 5.Oil 6.Print the
READ op
If op==1 Item.apppend(Fruitname)
READ product
Price.append(Fruitprice)
name, quantity
Qty.append(FruitQty)
,price
If op==2 Item.apppend(Vegetablename
READ product
)
name, quantity
Price.append(Vegetableprice)
,price
Qty.append(VegetableQty)
12
If op==3 Item.apppend(Cosmeticsname)
READ product Price.append(Cosmeticsprice)
name, quantity Qty.append(CosmeticsQty)
,price
If op==4
READ product Item.apppend(Grains name)
name, quantity Price.append(Grains price)
,price Qty.append(GrainsQty)
If op==5 Item.apppend(Oilname)
READ Price.append(Oilprice)
product name, Qty.append(OilQty)
quantity ,price
IC in
range
(len(items)
PRINT
Item[IC],Qty[IC],Price
[IC],Price[IC]*Qty[IC
]
Bill_amount=Price[IC]
*Qty[IC]
13
PRINT
Bill_amount
STOP
14
PROGRAM
print("\t\tWelcome to \n***Kannan Departmental Store***")
print(" ------------------------------------")
Items=[]
Qty=[] Price=[]
print("***********Menu*************")
print('''
1. Fruits
2. Vegetables
3. Cosmetics
4. Grains
5. Oil
6. Exit
''')
Items.append(FruitName)
Price.append(FruitPrice)
Items.append(VegetableName)
Price.append(VegetablePrice)
15
VegetableQty=int(input("Enter the Quantity(KG) : "))
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)
Qty.append(OilQty) print("Do you have another item ,If yes print the
print('''
1. Fruits 2. Vegetables
3. Cosmetics 4. Grains
5. Oil 6. Exit
''')
print("\n*************Bill************") print("***Kannan
Departmental Store***")
print("----------------------------------------")
16
print("Date:%s"%date) print("Name of the
Number : %2s"%mobile)
print("-----------------------------------------")
print("Product\tQuantity\tPrice\tBill") for
IC in range(len(Items)):
bill_amount+=(Price[IC]*Qty[IC])
print("-----------------------------------------")
print("-----------------------------------------") print("Thank
17
OUTPUT
18
RESULT
Thus the program for calculating retail shop bill is executed and output is
verifiedsuccessfully.
19
EX.NO: 1 C
DATE: SINE SERIES
AIM
To write a 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
PSEUDOCODE
TASK: To calculate the sine series
BEGIN
SET pi=3.14
FLOWCHART
20
START
START
Factorial(n)
Factorial(n)
Sin(n)
Fact=1
Pi=3.14
i in
range(1,n+1)
Read x,n
Print x
Fact*=1
Print sin(x,n)
Return Fact
END
STOP
21
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
sine=sine+((x**(2.0*i+1))/factorial(2*i+1))*sign
return sine
22
OUTPUT
23
#Get a inputs of degree and range from the user
RESULT
Thus the program for finding sine series is executed and output is verified successfully.
24
EX.NO: 1 D
DATE: WEIGHT OF A STEEL BAR
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
PSEUDOCODE
TASK: To find the total weight of a steel bar
BEGIN
SET Dsquare=steelDiameter*steelLength
Weightofsteelpermeter=Dsquare/162
PRINT Weightofsteelpermeter
TotalWeightofSteel=(Dsquare*steelLength)/162
PRINT TotalWeightofSteel
END
END TASK
25
FLOWCHART
START
Read SteelDiameter,
SteelLen
Dsquare=
SteelDiameter*SteelDiameter
Weight_of_steel_per_meter
= Dsquare/162
Total_weight_of_steel=(
Dsquare*SteelLen)/162
PRINT
Total_weight_of_steel
STOP
PROGRAM
SteelDiameter = int(input("Enter The Length of the Steel Diameter(mm):"))
"{:.2f}".format(WeightofSteelPerMeter)
26
OUTPUT
27
print("Weight Of Steel Bar per Meter:", e, "kg/m")
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.
28
EX.NO: 1 E COMPUTEELECTRICAL CURRENT IN THREE
DATE: PHASE AC CIRCUIT
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
PSEUDOCODE
TASK: To compute electrical current in three phase AC circuit
BEGIN
PRINT root3
FLOWCHART
29
START
Newton_method(num,num
_iters=100)
READ a
i in range
(num_iters)
Iternum=num
Num=0.5*(num+a/num)
Num==
Break
iternum
Return num
STOP
30
START
START
Newton_method(num,
num_iters=100)
Threephase(voltage,
current,root3)
Threephase(voltag
e,current,root3) Kva=voltage*current
*root3
Read
voltage,current
Return kva
Print
voltage,current
STOP
Root3=newton_method
(3)
Print threephase
(voltage,current,
root3)
STOP
PROGRAM
def newton_method(number, number_iters = 100):
31
a = float(number) for i in
range(number_iters):
(number + a/ number) if
number==iternumber:
break
return number
def threephase(voltage,current,root3):
kva=voltage*current*root3
return kva
:",current,"Amps")
root3=newton_method(3)
RESULT
Thus the program for computing electrical current in three phase AC circuit is executed and
output is verified successfully.
32
OUTPUT
33
EX.NO: 2 A
DATE: EXCHANGE THE VALUE OF TWO VARIABLES
AIM
To write a python program to exchange the value of given variables.
ALGORITHM
Step 1:Start
Step 8: Stop
34
START
Read V1, V2
temp = V1
V1 = V2
V2 = temp
START
print V1, V2
swap_function(
V1 = V1^V2 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
35 V2
V1 = V1 –
FLOWCHART
PROGRAM
print("Enter two values to swap")
variable...") temp = V1
V1 = V1 ^ V2
V2 = V1 ^ V2 V1
= V1 ^ V2
global V1, V2
print("*"*40)
V1 = V1 + V2
{V2}".format(V1=V1, V2=V2))
36
RESULT
Thus, the program to exchange the value of given variables was executed and
output is verified successfully.
37
OUTPUT
38
EX.NO: 2 B
DATE: DISTANCE BETWEEN TWO POINTS
AIM
To write a python program to find distance between two points.
ALGORITHM
Step 1: Start
Step 7: Stop
39
FLOWCHART
START
newton_method
Read x
i in range
(newton_method)
False
iternumberTrue
= number
False
return number
STOP
40
START START
newton_method distance_between(pointA,point
B)
(number, number_iters = 100)
distance_between(pointA,point x1,y2=pointA
B)
x2,y2=pointB
read
distx=x2-x1
pointA,pointB
disty=y2-y1
print root_2=newton_method(distx**2+disty**
distance_between 2)
(pointA,pointB
return
round(root_2,2)
STOP
STOP
PROGRAM
def newton_method(number):
x = float(number)
yn=number
for i in range(100):
41
yn1=yn yn
if yn==yn1:
break
distance_between(pointA, pointB):
x1, y1 = pointA
x2, y2 = pointB
distx = x2 - x1
disty = y2 - y1
RESULT
Thus, the python program to find distance between two points was executed and output is
verified successfully.
42
OUTPUT
43
EX.NO: 2 C
DATE: CIRCULATE THE VALUES OF N VARIABLES
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
44
FLOWCHART
START
Read n
Print lis1
Circulate (Nvalues)
Circulate (list1)
STOP
45
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
46
OUTPUT
47
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=GetNValues(n)
RESULT
Thus, thepython program to get an input from user and circulate N values was executed and
output is verified successfully.
48
EX.NO: 3 A
DATE: NUMBER SERIES
AIM
To write a program to find the number series.
ALGORITHM
Step 1: Start
Step 2: Read n value from the user
Step 3: Assign sum is 0
Step 4: IF choice == 1 THEN
FOR n in range(1,n+1)
sum <-sum+n
PRINT(sum) THEN
IF choice == 2 THEN
sum<-sum+n**2
PRINT(sum)
IF choice == 3 THEN
PRINT(sum) Step
5: Stop
PROGRAM:
N = int(input("Enter a number of a element:")) choice
= int(input("""
Number Series
49
1.sum of the n=N series - 1+2+3+4...........N
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
Thus, the above program for finding the number is executed and the output is verified
successfully.
50
OUTPUT
51
AIM
EX.NO:
DATE:
3B
NUMBER PATTERN
ALGORITHM
Step1: Start
IF n%2! = 0 THEN
PRINT(n)
IF choice == 2 THEN
IF N%2 == 0 THEN
PRINT(n) Step4:
Stop
PROGRAM
n = int(input("Enter the N value:)) choice
= int(input('''
Number Pattern
== 1:
for n in range(1,n+1):
52
if n%2!=0:
print(n) if choice == 2:
for n in range(1,n+1):
if n%2 == 0:
print(n)
OUTPUT
RESULT
Thus, the program coding has been executed and output is verified successfully. 3 C
PYRAMID PATTERN
53
AIM
EX.NO:
DATE:
ALGORITHM
Step1: Start
Step2: Get the (N) height value of the pyramid rows from the user.
Step5: Once the inner loop ends and we print new line and start printing * in a new line.
PROGRAM
N = int(input("Enter the N value:"))
print("\nPyramid pattern") for row
in range(N): for column in
range(row+1):
print("*",end=" ")
print("\n") print("\nStar
right triangle") for row in range(N):
for column in range(row+1):
print("*",end=" ")
RN = N-(row+1)
print("\nNumber pattern")
number = 1 for row in
range(N+1):
54
print("\n") print("\nstring pattern")
asciivalue += 1
OUTPUT
RESULT
Thus, the programto find the pyramid pattern has been executed andoutput is verified
successfully.
4A
LIBRARY MANAGMENT SYSTEM
55
AIM
EX.NO:
DATE:
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("\n"," "*10,"KiTE Library
choice=int(input(('''
1.Add Book
2.Delete Book
4.Issue Book
5.Return Book
56
while choice: if choice==1:
print("#"*20) print("
"*5,"Add Book")
print("#"*20)
BooksCatelogue.append(getBookName)
if choice==2:
print("#"*20) print("
"*5,"Delete Book")
print("#"*20)
BooksCatelogue.remove(getBookName) if
choice==3:
print(" "*5,"#"*20)
print("#"*20)
print(sno,"-",book,"-",BooksCatelogue.count(book),"Available")
print("#"*20)
57
getBookName=input("Enter Book Name : ")
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
58
OUTPUT
RESULT
Thus, the program for library management system is executed and output is verified
successfully.
4B
59
AIM
EX.NO:
DATE:
COMPONENTS OF A CAR
To write the program to check the working condition of car engine components in
percentage.
ALGORITHM
Step 1: START
Step 7: STOP
PROGRAM
60
OUTPUT
RESULT
61
AIM
EX.NO:
DATE:
Thus, the above program for checking the working condition of car engine component in
percentage is executed and output is verified successfully.
4C MATERIALS REQUIRED FOR CONSTRUCTION OF
A BUILDING
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, Steelbars = 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]
62
print("-----MATERIALS NEEDED FOR BUILDING ",AREA," Sqft HOUSE-----")
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)
OUTPUT
63
AIM
EX.NO:
DATE:
RESULT
Thus, the aboveprogram for the materials requirement to construct the building for the given
area is executed and output is verified successfully.
5A
COMPONENTS OF AUTOMOBILE
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
Step 6: Display the Genuine HSN code and non-Genuine HSN code.
Step 7: STOP
PROGRAM
print(" \tAutomobile Genuine Components Checker") print("%"*50)
APPROVED_HSN={'HSN0029','HSN0045','HSN0043','HSN0076','HSN098'}
HSNCode=set({})
GC in range(1,ComponentCount+1):
64
HSNCode.add(input(f"Enter the HSNCode of Component {GC}: "))
enumerate(HSNCode.intersection(APPROVED_HSN),start=1):
in enumerate(HSNCode.difference(APPROVED_HSN),start=1):
print(sno,code)
OUTPUT
RESULT
Thus, the above program to check the genuine automobile components is executed and the output is
verified successfully.
65
EX.NO: 5 B DATE: ELEMENTS OF CIVIL STRUCTURE
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'}
enumerate(elements,start=1): print(NO,'-',GE)
op(General_Elements)
66
Element=input(f"Enter the Element{Get_Element}: ")
else:
print("\n --- Common Elements in Your Building & General Elements --- ")
op(set(Elements.keys())|General_Elements)
67
OUTPUT
RESULT
Thus, the above programto find the elements of civil structure is executed and output is verified
successfully.
68
EX.NO:
DATE:
6A
FACTORIAL OF A NUMBER
AIM
To write a program to calculate factorial of a number.
ALGORITHM
Step 1: START
= 1, fact = 1
Step 8: STOP
PROGRAM
#factorial print("*"*20,"Factorial of Number
if num==1:
return num
else:
return num*factorial(num-1)
print(f"Factorial of '{num}'is",factorial(num))
69
OUTPUT
RESULT
Thus, the above program for calculating factorial of a number is executed and output is
verified successfully.
70
EX.NO:
DATE:
6B
LARGEST NUMBER IN A LIST
AIM
To write a program to find the largest number in a list.
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 =
indexes[idx:]: if
71
OUTPUT
RESULT
Thus, the above program for finding largest number in a list is executed and output is verified
successfully.
72
EX.NO:
DATE:
6C
AREA OF SHAPE
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):
rectangle(l,w):
circle(r,pi=3.14):
73
triangle(b,h):
parallelogram(b,h):
isosceles_trapezoid(a,b,h):
return (1/2)*(a+b)*h
def rhombus_kite(d1,d2):
return (1/2)*d1*d2
1.square
2.rectangle
3.circle
4.triangle
5.parallelogram
6.isosceles trapezoid
7.rhombus
8.kite
if choice==1:
choice==2:
74
print(f"Area of Rectangle : {rectangle(float(l),float(w))}") if
choice==3:
d1,d2=input("Enter the 'distance 1' and 'distance 2' value of rhombus : ").split()
d1,d2=input("Enter the 'distance 1' and 'distance 2' value of kite : ").split()
75
OUTPUT
76
RESULT
Thus, the above program for calculating area of the shape is executed and output is verified
successfully.
EX.NO: 7 A
DATE: CHECKING PALINDROME IN A STRING OF SHAPE
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
77
PROGRAM
string=input ("Enter the string : ")
rstring=string [::-1] if
string==rstring:
OUTPUT
RESULT
Thus, the aboveprogram to check the give string is palindrome or nothas executed and output
has been verified successfully.
EX.NO: 7 B
DATE: COUNTING CHARACTERS IN A STRING
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
78
Step 6:stop
PROGRAM
string=input("Enter the string : ")
charCount=0
OUTPUT
RESULT
Thus, the above program to find the character count of a string has executed and output has
been verified successfully.
EX.NO: 7 C
DATE: REPLACING A CHARACTERS IN A STRING
AIM
To write a program to replace a character in a string.
ALGORITHM
Step 1: Start
79
Step 8: Stop
PROGRAM
string=input("Enter the string : ") print("The Given String :
replace ? - "))
range(len(stringlist)): if
stringlist[idx]==charChange:
stringlist[idx]=repString
",ReplacedString.join(stringlist))
OUTPUT
RESULT
Thus, the above programto replace a character in a string has been executed and output has
been verified successfully.
80
EX.NO: 8 A STUDENT MARK SYSTEM USING NUMPY AND
DATE: PANDAS
AIM
To write a Python program to print the student mark system using numpy and panda library.
INSTALLING PACKAGES
81
PROGRAM
import os os.environ['MPLCONFIGDIR'] = os.getcwd() +
#code here d
={
'RollNumbe
r':[1,2,3,4],
'StudentName':['kamal','vimal','vinoth','wahi'],
82
'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)
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)
83
OUTPUT
84
RESULT
Thus, the above program for printing student mark system using numpy and pandas is
executed and the output is verified successfully.
85
AIM
EX.NO:
DATE:
8B
LINEAR REGRESSION USING SCIPY
PROGRAM
import os
x = np.random.random(10) y
= np.random.random(10)
squared:", r_value**2)
86
OUTPUT
RESULT
Thus, the above program for printing linear regression using scipy is executed and the output
is verified successfully.
87
AIM
EX.NO:
DATE:
A
9 COPYTHE CONTENT FROM ONE FILE TO
ANOTHER FILE
To FindCopy the Content from One File to anotherFile 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+')
of2.close()
import shutil
88
OUTPUT
RESULT
Thus, the Python Programto findCopy the Content from One File to anotherFile of a Given
Number and Termis executed and output verified successfully.
9B
WORD COUNT
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+',
len(words))
uniquewords=set(words) for
uniqueword in uniquewords:
print(uniqueword)
89
AIM
EX.NO:
DATE:
print("number of unique words in textfile :", len(uniquewords))
RESULT
Thus, the above programto word count in a file is executed and output is verified
successfully.
90
Th
EX.NO: 9 C
DATE: LONGEST WORD IN A TEXT FILE
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]
len(word)>len(longword):
OUTPUT
RESULT:
us, the above program to find longest word in a text file is executed and output has been
verified successfully.
EX.NO: 10 A
DATE: DIVIDE BY ZERO ERROR
91
AIM
To write program to divide by zero error by exception handling.
ALGORITHM
Step1:START
PROGRAM
print(f"{'*'*30} Division Operation {'*'*30}")
quotient=dividend/divisor
op=quotient except
ZeroDivisionError as error:
op=error finally:
92
Th
OUTPUT
RESULT
us, the python programto divide by zero error by exception handling is executed and
output is verified.
EX.NO: 10 B
DATE: VOTER’S AGE VALIDATION
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 Step5:
93
PROGRAM
print(f"{'*'*30} Voter ID Validation System {'*'*30}\n")
try :
fo=open('peoplelist.txt','r')
peoplelist=fo.readlines()
as e:
peoplelist:
name,age=people.split(' ')
if int(age)>=18:
else:
else
print(error)
OUTPUT
94
Th
RESULT
us, the python programto check voter age validity is executed and output is verified.
EX.NO: 10 C
DATE: STUDENT MARK RANGE VALIDATION
AIM
To write a python program to perform students marks range validation.
ALGORITHM
Step1:START
Step3: If mark is <0 or >100 then print that the value is out of range and try again.
PROGRAM
import re print(f"{'*'*30} Student Mark Range Validation
{'*'*30}\n")
try :
95
fo=open('studentmarklist.txt','r')
studentmarklist=fo.readlines()
error=e
finally: if
not error:
RollNumber,Name,MarksPercentage=tuple(re.findall('\w+',student))
else:
print(RollNumber," - 'fail'")
else:
print(error)
OUTPUT
96
Th
RESULT
us, the python program to perform students marks range validation is executed and output
is verified.
EX.NO: 11
DATE: PYGAME TOOL BASICS
AIM
To write a program to create pygame using pygame library.
INSTALLING PACKAGES
1.Go to this link to install pygame www.pygame.org/download.html.
97
PROGRAM
import pygame from
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() screen =
98
OUTPUT
RESULT
Thus, the above programto create pygame using pygame library has been executed and output
is verified successfully.
EX.NO: 12
DATE: BOUNCING BALL USING PYGAME
AIM
To write a program to bounce a ball using pygame library.
PROGRAM
import sys, pygame pygame.init()
'''logo = pygame.image.load("logo.png")
pygame.display.set_icon(logo)'''
99
pygame.display.set_caption("Bouncing Ball")
screen = pygame.display.set_mode(screen_size)
= pygame.image.load("1.jpg")
ball_rect = ball.get_rect()
pygame.event.get(): if
event.type == pygame.QUIT:
pygame.quit()
sys.exit()
ball_speed[1] = -ball_speed[1]
# Screen update
screen.fill(black)
screen.blit(ball, ball_rect)
pygame.display.flip()
100
OUTPUT
RESULT
Thus, the above program to bounce a ball using pygame library has been executed and output
is verified successfully
101