0% found this document useful (0 votes)
12 views

Pspp Lab Manual Updated

Uploaded by

aswinvino458
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Pspp Lab Manual Updated

Uploaded by

aswinvino458
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

EX.

NO: 1A DEVELOPING FLOWCHART FOR ELECTRICITY BILLING


DATE:

AIM:

Write an algorithm to calculate electricity bill amount with given units consumed

and to develop the flowchart for the same.

ALGORITHM:

Step 1 : Start

Step 2 : Read n unit

Step 3 : If the units 0 <= 100 then go to step 4 Else go to step 5

Step 4 : Total cost = (0 * 100) then go to step 11.

Step 5 : If units 0 <= 200 go to step 6 else go to step 7.

Step 6 : Total cost = (Unit - 100) * 1.5, then go to step 11

Step 7 : If the units 0 <= 500 go to step 8 else go to step 9

Step 8 : Total cost = ( (0 * 100) + ( (200 - 100) * 2 ) + ( (Unit - 200) * 3 ) ),then go to

step 11

Step 9 : If the units are above 500 go to step 10

Step 10 : Total cost = ( (0 * 100) + ( (200 - 100) * 3.5) + ( (400 - 100) * 4.60) +

( (Unit – 500) * 6.60) )

Step 11 : Print " Total Cost "

Step 12 : Stop.
FLOWCHART start

Read Units

Yes NO
Unit<=100

NO
Yes
Amount = Unit<=200
100*0

Yes NO
Amount = (100* 0) + Unit<=500
(Unit – 100)*1.5

Amount = (100* 0) + Amount = (100* 0) +


(200– 100)*2 + (200 – 100)*3.5 + (500 –
(Unit – 200)*3 200)* 4.6+(Unit – 500) *
6.6

Print Amount

Stop

RESULT :

Thus an algorithm and flowchart to calculate the electricity bill was developed
successfully.
EX. NO: 1B RETAIL SHOP BILLING

DATE:

AIM:

To develop an Algorithm and Flowchart for retail shop billing.

ALGORITHM:

Step 1 : Start

Step 2 : Read the value of n

Step 3 : Read the fixed price in each product.

Step 4 : Rate = (No.of products * cost) + Number

Step 5 : If Rate >= 500, go to step 6 Else go to step 7.

Step 6 : Amount = Rate + 2% of rate

Step 7 : Print Amount

Step 8 : Stop
FLOWCHART

Start

Tax=0.18

Rate_of_item

Display Items

Read
Quantities

Cost=Rate_of_item *
quantity+Rate_of_item*quantity+
……………..

Bill Amount=cost+cost*tax

Print BillAmount

Stop

RESULT:

Thus an algorithm and flowchart to calculate the retail shop billing was
developed successfully.
EX.NO: 1C SINE SERIES

DATE:

AIM:

To write an algorithm to evaluate the sine series and develop the flowchart for
the same.

ALGORITHM:

Step 1 : Start

Step 2 : Read the values of x and terms

Step 3 : Initialize, n = 1

Step 4 : Assign t = x and sum = x

Step 5 : If n <= terms, then go to step 6 else go to step 8.

Step 6 : t =(( t * (-1) * x * x ) / ( 2 * i * (2 * i + 1) ))

Step 7 : Sum = sum + t

Step 8 : Print sum

Step 9 : Stop
FLOWCHART:

Start

Read x,n

x=x*3.14159/180;

t=x;su
m=x;

i=1; i<=n; i++

t=(t*(-1)*x*x)/(2*i*(2*i+1));
sum=sum+t;

Print sum as sine(x)

Stop

RESULT:

Thus an algorithm and flowchart to calculate the sine series was developed
successfully.
EX.NO: 1D WEIGHT OF MOTOR BIKE

DATE:

AIM:
To write an algorithm to calculate the weight of motor bike and develop the
flowchart for the same.

ALGORITHM:

Step1: Start

Step2: Read the mass of motor bike

Step3: Calculate the weight of motor bike usingthe formula W = M*9.8


Step4: Print the calculated Weight(W)
Step5: Stop
FLOWCHART

RESULT :

Thus, the flow chart and an algorithm for calculating weight of motor bike is developed
Successfully.
EX. NO: 1E WEIGHT OF A STEEL BAR

DATE:

AIM:

To write an algorithm to calculate the weight of a steel bar and develop a


flowchart for the same.

ALGORITHM:

Step 1 : Start

Step 2 : Read diameter ( D ) of a steel bar

Step 3 : Read the length ( L ) of a steel bar

Step 4 : Calculate weight ( W ) W = ( D * D * L ) / 162

Step 5 : Print weight

Step 6 : Stop
FLOWCHART

Start

Read Diameter D

W =D2/162

Print W

Stop

RESULT :

Thus an algorithm and flowchart to calculate the weight of a steel bar was
developed successfully.
EX.NO: 1F Compute Electrical Current In Three Phase Ac Circuit

DATE:

AIM:

To write an algorithm for electric circuit in three phase AC circuit and develop
the flowchart for the same.

ALGORITHM:

Step 1 : Start

Step 2 : Read pf.V.I

Step 3 : Power = root of 3 * pf * V * I

Step 4 : Print Power

Step 5 : Stop
FLOWCHART

Star
t

Read voltage ‘v’,


Current ’I’, Power
factor ‘PF’

Power = (V*I*PF*1.732)

Print(“Power”)

Stop

RESULT :

Thus, an algorithm and flowchart to calculate electric current in three phase AC


circuit was developed successfully.
EX.NO: 2 PYTHON PROGRAMMING USING SIMPLESTATEMENTS
AND EXPRESSION
DATE:

2A) EXCHANGE THE VALUE OF TWO VARIABLES

AIM:
To write a program to exchange the values of two variables.

ALGORITHM:
STEP 1: Start

STEP 2: Read the values for ‘a’ and ‘b’

STEP 3: Print the values of ‘a’ and ‘b’ before swapping

STEP 4: t=a

STEP 5: a=b

STEP 6: b=t

STEP 7: Print interchanged values ‘a’ and ‘b’ after swapping.


STEP 8: Stop
FLOWCHART
start

Read a,b

Print a,b
before swapping

t= a
a=b
b=t

Print a,b
after swapping

Stop
PROGRAM:

a=int(input("Enter first number:"))

b=int(input("Enter second number:"))

print("Before Swapping")

print("a=",a)
print("b=",b)
t=a
a=b
b=t
print("After Swapping")
print("a=",a)
print("b=",b)

RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 2B CIRCULATES THEVALUES OF “N” VARIABLES

DATE:

AIM:
To write a python program to circulates the values of “N” variables.

ALGORITHM:

Step 1 : Start

Step 2 : Input the value of “N”

Step 3 : Using slice operator we can continue the step until all the values are

circulated using B=A[i:]+A[:i]

Step 4 : Print B

Step 5 : Stop
FLOWCHART:
PROGRAM:
defcirculate(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)

RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 2C DISTANCE BETWEEN THE TWO POINTS

DATE:

AIM:
To write a program to find the distance between two points.

ALGORITHM:
step 1: start

step 2: read the co-ordinates of first and second points


step 3: compute the distance using the formula ((x1-x2)*(x1-x2)+(y1-y2)*(y1-
y2))**0.5
step 4: print distance

step 5: stop
FLOW CHART:
PROGRAM:
Import math

x1 = int(input("Enter a x1: "))

y1 = int(input("Enter a y1: "))

x2 = int(input("Enter a x2: "))

y2=int(input("Enteray2:"))

distance==((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5

print("Distance= ",distance)

RESULT:
Thus, the given program was executed successfully and the output is obtained.
EX.NO: 3 Programs Using Conditionals and Iterative Statements
DATE:
3A) TO DISPLAY ODD SERIES

AIM:

To write a python program that displays odd numbers up to a given limit.

ALGORITHM :

Step1 : Start

Step2 : Get the value of n

Step3 : for i in range(1,n+1,2):

Step4 : Print(i)
Step5 : Stop
PROGRAM:

n = int(input("Enter the value of n:"))

for i in range(1, n+1, 2):

print(i)

Result :

Thus the program was executed successfully and the output was verified .
Ex.No: 3B NUMBER PATTERN
DATE:

AIM:
To write a python program to print the number pattern.
ALGORITHM:
Step 1 : Start
Step 2 : Read N
Step 3 : i in range(1,N+1),then go to step 4 else go to step 17
Step 4 : k in range (N,i,-1)then go to step 5
Step 5 : print ('' '')
Step 6 : Repeat the step 4 until the condition become false
Step 7 : If the condition is false , then go to step 8
Step 8 : j in range (1,i+1)
Step 9 : print j
Step 10 : Repeat the step 8 until the condition become false
Step 11 : If the condition is false , then goto step 12
Step 12 : i in range (i-1,0,-1)
Step 13 : print i
Step 14 : Repeat the step 12 until the condition become become false
Step 15 :If the condition is false ,then go to step 16
Step 16 :print Number pattern
Step 17 : Stop
PROGRAM:

N =5

For i in range(1,N+1):

for k in range(N,i, –1):

print("",end =' ')

for j in range(1,i+1):

print(j, end='')

for i in range(i-1,0,-1):

print(l,end='')

print()

RESULT :

Thus the program was executed successfully and the output was verified .
EX.NO: 3C PRAMID PATTERN
DATE:

AIM:
To write a python program to print the pyramid pattern.
ALGORITHM :
Step 1 : Start
Step 2 : Read n , m
Step 3 : Calculate m = (2*n) - 2
Step 4 : i in range (0 , n)
Step 5 : j in range (0 ,m), then continue the step 6
Step 6 : Calculate m= m - 1
Step 7 : j in range (0 , i+1),then go to step 8 else go to step 10
Step 8 : print(' * ')
Step 9 : Repeat the step 7 until the condition become false
Step 10 : Stop
PROGRAM:

n = int(input("Enter the number of rows: "))

m=(2*n)-2

for I in range(0,n):

for j in range(0,m):
print(end="")
m=m-1

for j in range(0,i+1):

print("*",end='')

print(" ")

RESULT :
Thus the program was executed successfully and the output was
verified.
EX.NO: 4A OPERATIONS OF LISTS
DATE:

AIM:
To perform operations in Materials required for construction of a building using
lists

ALGORITHM:

Step 1: start

Step 2: create a list

Step 3: Perform indexing operation

Step 4: Perform slicing operation

Step 5: Perform append operation

Step 6: Perform extend operation

Step 7: change third element in a list

Step 8: Perform delete operation

Step 9: Perform remove operation

Step 10: find length of list


PROGRAM:

# create a list

List_name=['Brick','Cement','Wooden frame','gravel','tiles']

# access item at index 0

print('positive index- index 0 :',List_name [0])

print('Negative indexing index -5 :',List_name [-5])

# items from index 2 to index 4

print('items from index 2 to index 4 :',List_name [2:5])

# using append method

print("Before Append :", List_name)

List_name.append(‘wires’)

print("After Append :", List_name)

List_name1=['sand','glass'] # join two lists

List_name.extend(List_name1) print("After Extend :", List_name)

# changing the third item to 'C' List_name [2] = 'ironframe'

print(“changing the third item to ironframe :”, List_name )

# delete first two items del List_name [0 : 2]

print('After deleting first two items :', List_name ) # remove from the list
List_name.remove('ironframe')

print('After removing ironframe :', List_name ) #list length

print("Total Elements in a list: ", len(List_name))

RESULT :

Thus the program was executed successfully and the output was verified.
EX.NO: 4B OPERATIONS OF TUPLE
DATE:

AIM:
To perform operations in Components of a car using tuple

ALGORITHM:
Step 1: start
Step 2: create a tuple
Step 3: Perform indexing operation
Step 4: Perform slicing operation
Step 5: Perform append or concatenate operation
Step 6: Perform delete operation
Step 7: Perform repeat operation
Step 8: find length of tuple
PROGRAM:

# create a Tuple

Tuple_name=('gear','break','power steering','AC','Tyre')

# access item at index 0

print('positive index- index 0 :',Tuple_name [0])

print('Negative indexing index -5 :',Tuple_name [-5])

# items from index 2 to index 4

print('items from index 2 to index 4 :',Tuple_name [2:5])

# using append method

print("Before Append :", Tuple_name)

Tuple_name1 = (‘wires’, 'wiper' )

print("After Append :", Tuple_name + Tuple_name1)

# delete first two items del Tuple_name1

# repeat tuple

Tuple_name1 =Tuple_name*2 print('After repeating :', Tuple_name1) #list


length

print("Total Elements in a list: ", len(Tuple_name1))

RESULT :

Thus the program was executed successfully and the output was verified.
EX.NO:5A OPERATIONS OF SETS & DICTIONARIES

DATE:

AIM:

To write a python program to implement the operations in a language using sets.

PROGRAM:

language1={'C','C++','JAVA'}
language2={'VB','PYTHON','ORACLE','JAVA'}
print(language1)
print(language2)
language1.add('SQL')
print(language1)
language1.remove('SQL')
print(language1)
print(language1 | language2)
print(language2.union(language1))
print(language1 & language2)
print(language1.intersection(language2))
print(language1 -language2)
print(language2.difference(language1))
print(language1 ^ language2)

RESULT :

Thus the program was executed successfully and the output was verified.
EX.NO:5B OPERATIONS OF SETS & DICTIONARIES

DATE:

AIM:

Implementing real-time/technical applications Components of an


automobile using Dictionaries

PROGRAM:

components = {"Brake": 2,"Tyre": 4,"Steering": 1}

print(components)

x = components.copy()

print(x)

x = components.get("Tyre")

print(x)

x = components.items()

print(x)

components.update({"color": "White"})

print(components)

x = components.pop("Brake")

print(x)

print(components)

x = components.setdefault("Brake", "Tyre")

print(x)

print(components)

x = components.values()

print(x)

y=1

thisdict = dict.fromkeys(components, y)
print(thisdict)

x = components.keys()

print(x)

components.clear()

print(components)

RESULT :

Thus the program was executed successfully and the output was verified.
EX.NO: 6 PROGRAMS USING FUNCTIONS

DATE:

6A. FACTORIAL OF A NUMBER

AIM:
To write a python program, algorithm and flow chartfor factorial using recursion
function.

ALGORITHM:

Step1: Start

Step2: Read n

Step3: Call the function fact(n)

Step4: Print the result obtained from the function


Step5: Stop

ALGORITHM FOR FUNCTION FACT(N):


Step1: Start

Step2: if n = 0, then return 1 else go to step 3


Step3: calculate x = n*fact(n-1)

Step4: return x
FLOW CHART:

Star
t

Read n

y = fact(n)

Print(y)

Stop
FLOW CHART FOR FUNCTION FACT(N):

fact(n)

No If
Yes
n==0

return 1 return (n*fact(n-1))


PROGRAM:

def fact(n): if n == 0:
return 1
else:
x = n*fact(n-1)
return x
n = int(input("Enter a value:"))
y = fact(n)
print(y)

RESULT:
Thus the program, algorithm and flowchart for factorial using function is made
successfully
EX.NO: 6 PROGRAMS USING FUNCTIONS

DATE:

6B. LARGEST NUMBER IN A LIST

AIM:
To write a python program to find the largest number ina list using function.

ALGORITHM:
Step1: Start

Step2: Read the list N

Step3: Call the function max(N)

Step4: print the maximum number

Step5: Stop

ALGORITHM FOR THE FUNCTION:


Step1: Start

Step2: Set max = N[0]

Step3: For i in N

Step4: If I > max, then

Step5: return max

Step6: Stop
FLOWCHART:

Start

Read the list N

Call the function max(N)

Print the maximum number in


the list
list

Stop
FLOWCHART FOR FUNCTION MAX(N):

max(N)

max = N[0]

False
for i in N

True

If i >

False max

True

max = i

return max
PROGRAM:

def max(N):
max = N[0]
for i in N:
if i > max:
max = i

return max
N = [99, 76, 43, 56, 34]
print("Maximum number = ", max(N))

RESULT:
Thus, the program to find the largest number in a listwas executed successfully.
EX.NO: 6C PROGRAMS USING FUNCTIONS

DATE:

6C. FIND AREA OF SHAPE

AIM:
To write a python program to find the area of shapes.

ALGORITHM:

Step1: Start

Step2: Input the choice

Step3: If choice = =1,then call


RectngleArea()

Step4: elif choice = = 2,then call SquareArea()


Step5: else print(no shape found)

Step6: Stop

ALGORITHM FOR RectngleArea()

Step1: Start
Step2: Input the breadth(b)

Step3: Input the length (l)

Step4: Calculate A= l*b

Step5: print A

ALGORITHM FOR SquareArea()

Step1: Start
Step2: Input the side of square

Step3: Calculate A = a*a

Step4: print A
PROGRAM:
def RectangleArea():
l = int(input("Enter l:"))
b = int(input("Enter b:"))
A=l*b
print("Area of rectangle", A)

def SquareArea():
a = int(input("Enter a:"))
A=a*a
print("Area of square", A)
choice = int(input("Enter a choice:"))

if choice == 1:
RectangleArea()
elif choice == 2:
SquareArea()
else:
print("No shape found")

Flow Chart for TriangleArea() &SquareArea:

RectangleArea() SquareArea()

Input length(l), Input side(a)


breadth(B)

A = l*b A = a*a

Print(A) Print(A)
FLOWCHART:

Start

Read choice

If

Yes Choice ==1 No

elif choice= = 2 No

CallRectangleArea() Yes

Call SquareArea() print(“no


shape found”)

Stop

RESULT:
Thus the python program to calculate shapes using function was executed
successfully.
EX.NO: 7 PROGRAMS USING STRINGS

DATE:

7A. TO REVERSE A GIVEN STRING

AIM:
To write a python program to reverse a given string.

ALGORITHM:

Step1: Start

Step2: Input a word

Step3: Reverse the given string using slice operator andstore it in a variable.
Step4: print the reversed string

Step5: Stop

PROGRAM:

word = input("Enter a word:")

rev_word = word[::-1]

print(rev_word)

RESULT:

Thus, the program to reverse a string is successfullyexecuted and output is obtained.


EX.NO:7 PROGRAMS USING STRING

DATE:

7B. PALINDROME OR NOT

AIM:

To write a python program to check whether the givenword is palindrome or


not.

ALGORITHM:

Step1: Start

Step2: Input a word from user

Step3: Reverse the given string using slice operatorand store it in a variable.
Step4: Check if the reversed string and originalstring are same
Step5: if they are same then print “It is apalindrome”
Step6: else print “Not a palindrome”
Step7: Stop
PROGRAM:

word = input("Enter a word:")


rev_word = word[::-1]
if(word = = rev_word):
print("It is a palindrome")
else:

print("It is not a palindrome")

RESULT:

Thus, the program to check if the input word is a palindrome is executed


successfully and the output is obtained.
EX.NO:7 PROGRAMS USING STRING

DATE:

7C. COUNT CHARACTERS IN A STRING


AIM:

To write a python program to count characters in a string.

ALGORITHM:

Step1: Start

Step2: Get a word from the user

Step3: Ask the user to input the character theywant to get count for
Step4: Initialize a variable named “count”
Step4: For each character in the word provided by the user, check if it
matches the character the user has entered
Step5: if it matches then, increment “count” by one
Step6: Print the variable count

Step7: Stop
PROGRAM:
word = input("Enter a word:")
letter = input("Enter the character :")

count = 0
for char in word:
if char == letter:

count += 1
print("The letter ",letter,"appears",count,"times inthe word")

RESULT:
Thus the program to count the number of characters in a string is executed
successfully andoutput is obtained.
EX.NO:7 PROGRAMS USING STRING

DATE:

7D. REPLACE A CHARACTER A STRING


AIM:
To write a python program to replace a character a string.

ALGORITHM:
Step1: Start
Step2: Input a word from user
Step3: Input the old character that the user want to replace
Step4: Input new character for replacing
Step5: Create an empty string and store it in a variable
Step6: For every character in the word given by user check it is equal to
the old character that the user want to replace.
Step7: If equal then, add the new character to the new string
Step8: Else add the current character to the new string
Step9: Print the new string
Step10: Stop
PROGRAM:
word = input("Enter a word:")
old_char = input("Enter the character you want to replace:")
new_char = input("Enter the new character:")

new_str = ""
for char in word:
if char == old_char:

new_str += new_char
else:
new_str += char

print(new_str)

RESULT:
Thus the program for replacing a character in a string is executed
successfully and output is obtained.
Ex: No:8 PYTHON STANDRAD LIBRARIES
DATE:
A) PANDAS

AIM:
Write a python program to implement python standard library (pandas).

ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import pandas python package and aliasing pandas as pd
STEP 3: Declare an empty list a and b
STEP 4: Read the number of employee and store it in d
STEP 5: Using for loop,
STEP 5.1: Get the employee id and append it in list a

STEP 5.2: Get the employee name and append it in list b


STEP 6: Declare a dictionary (e) with Employee_ id and Employee_ name as key and a and b as
values respectively
STEP 7: Using Data Frame ( ) from pandas python package, create a tabular data structure and
store it in df1
STEP 8: Print df1
STEP 9: Stop

PROGRAM:
import pandas as pd
a=[ ]
b=[ ]
d=int (input(‘Enter the number of employees:’))
for i in range (0,d):
y=int(input(‘Enter employees id: ‘))
a.append(y)
x=input(‘Enter name of employee:’)
b.append(x)
e={‘Employee_ id’:a,’Employee_ name’:b}
df1= pd.DataFrame(e,columns=[‘Employee_id’,’Employee_name’])
print(df1)

RESULT:
Thus, a python program to implement python standard library (pandas) was executed successfully.
EX.NO.8B NUMPY
DATE:
AIM:
Write a python program to implement python standard library (numpy).

ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import numpy python package and aliasing numpy as np
STEP 3: Declare array a and b
STEP 4: Add arrays sum (a+b), then
print arrays sum (a+b)
STEP 5: Multiply arrays a and b, then
print array multiplication (a*b)
STEP 6: Using dot ( ) operator multiply arrays a and b, then
print matrix multiplication (a.dot(b))
STEP 7: Divide arrays a and b, then
print array division (a\b)
STEP 8: Stop

PROGRAM:
import numpy as np
a=np.array ([[1,2],
[3,4]])
b=np.array ([[4,3],
[2,1]])
print (“Array sum:\n”,a+b)
print (“Array multiplication:\n”,a*b)
print (“Matrix multiplication:\n”,a.dot(b))
print (“Array division:\n”,a/b)

RESULT:
Thus, python program to implement python standard library (numpy) was executed successfully
EX.NO. 8C MATPLOTLIB

DATE:

AIM:

Write a python program to implement python standard library (matplotlit)

ALGRORITHM:
STEP 1: Start
STEP 2: Using import, we import matplotlib and pyplot, then we alias pyplot as plt
STEP 3: Using import, we import normal function from numpy.random python package
STEP 4: Using normal( ) function, we declare gaussian_ numbers
STEP 5: Using hist( ) function, we generate the histogram
STEP 6: Using title( ) function, give the title to the graph as Gaussian Histogram
STEP 7: Using xlabel( ) function, we label the x axis as value
STEP 8: Using ylabel( ) function, we label the y axis as Frequency
STEP 9: Using show( ) function, display the histogram
STEP 10: Stop

PROGRAM:
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers=normal(size=1000)
plt.hist(gaussian_numbers)
plt.title(“Gaussian Histogram”)
plt.xlabel(“Value”)
plt.ylabel(“Frequency”)
plt.show( )

RESULT:
Thus, a python program to implement python standard library (matplotlib) was executed
successfully
EX.NO.8D
DATE: SCIPY

AIM:
Write a python program to implement python standard library (scipy)

ALGORITHM:
STEP 1: Start
STEP 2: Using import, import special function from scipy python package
STEP 3: Using import, we import linaly function from scipy python package
STEP 4: Using import, we import numpy python package and aliasing numpy as np
STEP 5: Using cbrt( ) function, find the cube root of 27 and 64, then store it in cb
STEP 6: Print cb
STEP 7: Using exp( ) function, find the value of 10 to the power 3 and store it in a
STEP 8: Print a
STEP 9: Using exp( ) function, find the value of 2 to the power 3 and store it in b
STEP10: Print b
STEP11: Using sindy ( ) function, find the value of sin 90 and it in c
STEP12: Print c
STEP13: Using cosdg( ) function, find the value of cos 45 and store it in d
STEP14: Print d
STEP15: Declare an array (two_ d_ array)
STEP16: Using det ( ) function, find and print the determinant of the array
STEP17: Using inv ( ) function, find and print the inverse of the array
STEP18: Stop
PROGRAM:
from scipy import special
from scipy import linalg
import numpy as np
cb=special.cbrt([27,64])
print(cb)
a=special.exp10(3)
print(a)
b=special.exp2(3)
print(b)
c=special.sindg(90)
print(c)
d=special.cosdg(45)
print(d)
two_ d_array=np.array([[4,5],[3,2]])
linalg.det(two_d_array)
linalg.inv(two_d_array)

RESULT:
Thus, a python program to implement python standard library (scipy) was executed
successfully.
EX: NO:9 TECHNICAL APPLICATION USINGFILE
DATE: HANDLING

A) COPY CHARACTER FROM ONE FILE TO


ANOTHER

AIM:
Write a python program to copy character from one file to another.

ALGORITHM:
STEP 1: Start
STEP 2: Get the name of Source file in sFile

STEP 3: Get the name of Target file in tFile

STEP 4: Using open () function, open the source file (sFile) in reading mode

STEP 5: Using read () function, read the characters in texts

STEP 6: Using close () function, close the source file (sFile)

STEP 7: Again, using open () function, open the target file (tFile) in reading
mode
STEP 8: Using for loop in texts and using write () function, write the characters in
targets file (tFile)
STEP 9: Using close () function, close the target file (tFile)
STEP 10: Print File Copied Successfully

STEP 11: Stop


PROGRAM:
print ("Enter the name of Source file:")
sFile=input ()
print ("Enter the name of Target file:")
tFile=input ()
fileHandle=open (sFile, "r")
texts=fileHandle.readlines()
fileHandle.close()
fileHandle=open (tFile, "w")
for s in texts:
fileHandle.write(s)
fileHandle.close()
print("\n File Copied successfully!")

RESULT:
Thus, a python program to implement real-time application to copy characterfrom one file to another
using File Handling was executed successfully
EX: NO:9B WORD COUNT
DATE:
AIM:
Write a python program to implement real-time application to count the words in the text file
using file handling

ALGORITHM:
STEP1: Start
STEP2: Using import, we import counter function from collections python package
STEP3: Define the function word_count ()
STEP4: Get the filename in fname
STEP5: Using with keyword and open () function, open the file as f
STEP6: Using for loop in f,
Step6.1: Split the lines using split () function
Step6.2: Declare num_words=0
Step6.3: Using len () function, store the length of the characters in
num_words
STEP7: Print number of words (num_words)
STEP8: Print the number of each word count in the file(word_count)
STEP9: Stop
Function word_count ()
STEP1: Start
STEP2: Using with keyword and open () function, open the file as f
STEP3: Using counter (), read () and split () functions, we read and split the
characters and count the words respectively
STEP4: Stop

PROGRAM:
from collections import Counter
def word_count(fname):
with open(fname) as f:
return Counter (f.read().split())
fname=input ('Enter the file name:')
with open(fname) as f:
for line in f:
words=line.split()
num_words=0
num_words+=len(words)
print ('Number of words:', num_words)
print ('Number of each word count in the file:\n', word_count(fname))

RESULT:
Thus, a python program to implement real-time application to count the words using file
handling was executed successfully.
EX: NO:9C LONGEST WORD
DATE:

AIM:
Write a python program to implement real-time application to find the longest word in the text
file using file handling.

ALGORITHM:
STEP 1: Start
STEP 2: Define the function longest_words
STEP 3: Get the name of the file in filename
STEP 4: Print longest_words
STEP 5: Stop
Function longest_words ()
STEP 1: Start
STEP 2: Using with keyword, open the file as infile in reading mode
STEP 3: Using read () and split () function, we read and split the character, then
store it in words
STEP 4: Using len () function, find the maximum length of the character
STEP 5: Returns the longest word using for loop and if statement
STEP 6: Stop

PROGRAM:
def longest_words(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]

filename=input('Enter the name of file:')

print(longest_words(filename))

RESULT:
Thus, a python program to implement real-time application to find the longest word in the text
file using file handling was executed successfully
Ex: No:10 TECHINICAL APPLICATIONS USINGEXCEPTION HANDLING
DATE:
A).DIVIDE BY ZERO ERROR

AIM:
Write a python program to perform divide by zero error using exception handling.

ALGORITHM:
STEP1: Start
STEP2: Read the inputs x and y
STEP3: Using exception handling perform try block statements
STEP3.1: Perform z=x/y
STEP3.2: print the result of z
STEP4: Display the exception Zero division Error
STEP5: Stop

PROGRAM:
x=int(input("Enter the value of x="))
y=int(input("Enter the value of y="))
try:
z=x/y
print("Result=",z)
except ZeroDivisionError: print("Divide by zero Error")

RESULT:
Thus, the python program was executed successfully.
Ex: No:10B VOTER’S AGE VALIDITY
DATE:

AIM:
Write a python program to perform voter’s age validity using exception handling.

ALGORITHM:
STEP1: Start
STEP2: Call the function voter()
STEP3: Using exception handling perform try block statements
STEP4: Read the input age
STEP5: Check the condition
If(age>=18) then
Print eligible to vote
else
print not eligible to vote
STEP6: If any exception occur perform exception statement
STEP7: Stop

PROGRAM:
def voter():
try:
age=int(input("Enter your age="))
if(age>=18):
print("Eligible to vote")
else:
print("Not eligible to vote")
except ValueError:
print("Age must be valid number")
except IOError:
print("Enter correct value")
except:
print("An error occured")
voter()
RESULT:
Thus, the python program was executed successfully.
Ex: No: 10C STUDENT’S MARK RANGE VALIDATION

DATE:

AIM:
To write a python program to implement real time application to check student’s mark range
validation using Exception Handling.

ALGORITHM:
STEP1: Start
STEP2: In try block, print enter marks obtained in 5 subjects

STEP3: Get the values of s1, s2, s3, s4 and s5


STEP4: Using if statements, check whether the entered values are in the range of to 100.if not in
the range then,
STEP4.1: Raise ValueError respectively.

STEP5: In the final block,


print this is always executed
STEP6: Find the sum of all the entered values (s1,s2,s3,s4,s5) and store it in avg tot
STEP7: Find the average of the entered values and store it in avg

STEP8: Using if…elf statement, find the range of the average value as given below respectively

(i) 91 10 100
(ii) 81 to 91
(iii) 71 to 81
(iv) 61 to 71
(v) 51 to 61, then
STEP 8.1: Print any one of the statement according to the range of the average value
respectively,
(i) your grade is A
(ii) your grade is B
(iii) your grade is C

(iv) your grade is D


(v) your grade is E
STEP8.2: ELSE
Print your grade is F
STEP9: Stop
PROGRAM:
try:

print("Enter marks obtained in 5 subjects:")

S1=int(input())

if S1<0 or S1>100:

raise ValueError("The value is out of range")

S2=int(input())

if S2<0 or S2>100:

raise ValueError("The value is out of range")

S3=int(input())

if S3<0 or S3>100:

raise ValueError("The value is out of range")

S4=int(input())

if S4<0 or S4>100:

raise ValueError("The value is out of range")

S5=int(input())

if S5<0 or S5>100:

raise ValueError("The value is out of range")

finally:

print('This is always executed')

tot=S1+S2+S3+S4+S5

avg=tot/5

if avg>=91 and avg<=100:

print("Your Grade is A")

elif avg>=81 and avg<91:

print("Your Grade is B")

elif avg>=71 and avg<81:

print("Your Grade is C")

elif avg>=61 and avg<61:

print("Your Grade is D")

else:

print("Your Grade is F")


RESULT:
Thus, a python program to implement real time application to check student’s mark range
validation using Exception Handling was executed successfully.
Ex: No:11 ELLIPTICAL ORBITS USING PYGAME
DATE:
SIMULATE ELLIPTICAL ORBITS USING PYGAME
AIM:
Write a python program to simulate the elliptical orbits using pygame.

ALGORITHM:
STEP1: Start.
STEP2: Set the screen size and caption.
STEP3: Create clock variable.
STEP4: Set x and y radius of ellipse.
STEP5: Starting from degree 0 ending with 360 degrees in increments of 10 degrees
Calculate the (x1, x2) coordinates to find a find a point in the elliptical orbit
STEP6: Converts degree to radians (degree*2*math.pi/360)
STEP7: Draw center circle, ellipse and another smaller circle on the ellipse
STEP8: Refresh the screen every 5 clock ticks
STEP9: Repeats steps 4 to 8 untill user quits the program
STEP10: Stop
PROGRAM:
import pygame
import math
import sys
pygame.init()
screen=pygame.display.set_mode((600,300))
pygame.display.set_caption(“Elliptical orbit”)
clock=pygame.time.Clock()
while (True):
for event in pygame . event.get():
if event.type==pygame.QUIT:
sys.exit()
xradius=250
yradius=100
for degree in range (0,360,10):
x1=int(math.cos(degree*2*math.pi/360)*xradius)+360
x2=int(math.sin(degree*2*math.pi/360)*yradius)+150
screen.fill((0,0,0))
pygame.draw.circle(screen,(255,69,0),[300,150],40)
pygame.draw.ellipse(screen,(255,255,255),[50,50,500,200],1)
pygame.draw.circle(screen,(0,255,0),[x1,y2],20)
pygame.display.flip()
clock.tick(5)

RESULT:
Thus, a python program to simulate the elliptical orbits using pygame was executed
Successfully
Ex: No:12 BOUNCING BALL USING PYGAME
DATE:
BOUNCING BALL
AIM:
Write a python program to develop a game like bouncing ball using pygame tool.

ALGORITHM:
Step1: Start
Step2: Set screen size and background colour
Step3: Set speed of moving ball
Step4: Create a graphical window using set_mode()
Step5: Load the ball image and create a rectangle area covering the image
Step6: when the condition is true,the event is started with a time delay of 2 second
Step7: Move the Ball in specified speed
Step8: If ball hits the edges of the screen reverse the direction
Step9: Use blit() method to copy the ball in the rectangle screen and use flip() method to make
all images visible
Step10: Create an infinite loop and repeat steps 7 and 8 untill user quits the program
Step11: Stop
PROGRAM:
import sys, pygame
pygame.init()
size= width, height=700,250
speed=[1,1]
background=255,255,255
screen=pygame.display.set_mode(size)
pygame.display.set_captain(“Bouncing ball”)
ball=pygame.image.load(“ball.jpg”)
ballrect=ball.get_rect()
while 1:
pygame.time.delay(2)
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(background)
scren.blit(ball,ballrect)
pygame.diplay.flip()

RESULT:
Thus, a python program to develop a game like bouncing ball using pygame tool was executed
successfully.

You might also like