EX - 01
IDENTIFICATION AND SOLVING OF SIMPLE REAL LIFE OR SCIENTIFIC
OR TECHNICAL PROBLEMS, AND DEVELOPING FLOW CHARTS FOR THE
SAME.
(Electricity Billing, Retail shop billing, Sin series, weight of a motorbike, Weight of a steel
bar, compute Electrical Current in Three Phase AC Circuit)
Date: 1.A. Electricity Billing
Aim
To write a python program for the Electricity Billing.
Algorithm
Step 1: Start the program
Step 2: Read the input variable
“unit” Step 3: Process the following
When the unit is less than or equal to 100 units, calculate usage=unit*5
When the unit is between 100 to 200 units, calculate usage=(100*5)+((unit-100)*7)
When the unit is between 200 to 300 units, calculate usage=(100*5)+(100*7)+((unit- 200)*10)
When the unit is above 300 units, calculate usage=(100*5)+(100*7)+(100*!0)+((unit- 300)*15)
For further, no additional charge will be calculated.
Step 4: Display the amount “usage” to the user.
Step 5: Stop the program
Flowchart
Program
unit = int(input("Please enter Number of Unit you Consumed :
")) if(unit <= 100):
usage = unit * 5
elif(unit <= 200):
usage=(100*5)+((unit-100)*7)
elif(unit <= 300):
usage=(100*5)+(100*7)+((unit-200)*10)
else:
usage=(100*5)+(100*7)+(100*10)+((unit-300)*15)
print("Electricity Bill = %.2f" %usage)
print("Note: No additional charge will be calculated")
Result
Thus the Electricity Billing program has been executed and verified successfully.
Date: [Link] Shop Billing
Aim
To write a python program for the Retail Shop Billing.
Algorithm
Step 1: Start the program
Step 2: Initialize the values of the items
Step 3: Read the input like the name of item and quantity.
Step 4: Process the following amount=(item_name*quantity)
+amount
Step 5: Repeat the step4 until the condition get
fails. Step 6: Display the value of “amount”.
Step 7: Stop the program.
Flowchart
Program
print("Welcome to Riya Retail Shopping")
print("List of items in our market")
soap=60; powder=120; tooth_brush=40; paste=80;
perfume=250 amount=0
print("[Link]\[Link]\[Link] Brush\[Link] Paste\[Link]")
print("To Stop the shopping type number 0")
while(1):
item=int(input("Enter the item
number:")) if(item==0):
break
else:
if(item<=5):
quantity=int(input("Enter the quantity:"))
if(item==1):
amount=(soap*quantity)+amount
elif(item==2):
amount=(powder*quantity)+amount
elif(item==3):
amount=(tooth_brush*quantity)+amount
[Link](amount)
elif(item==4):
amount=(paste*quantity)+amount
elif(item==5):
amount=(perfume*quantity)+amount
else:
print("Item Not available")
print("Total amount need to pay
is:",amount) print("Happy for your visit")
Result
Thus the Retail Shopping Billing program has been executed and verified successfully.
Date: 1.C. Sin Series
Aim
To write a python program for sin series.
Algorithm
Step 1: Start the program.
Step 2: Read the input like the value of x in radians and n where n is a number up to which we
want to print the sum of series.
Step 3: For first term,
x=x*3.14159/180
t=x;
sum=x
Step 4: For next term,
t=(t*(-1)*x*x)/(2*i*(2*i+1))
sum=sum+t;
# The formula for the 'sin x' is represented as
# sin x= x-x3/3!+x5/5!-x7/7!+x9/9! (where x is in radians)
Step 5: Repeat the step4, looping 'n’' times to get the sum of first 'n' terms of the series.
Step 6: Display the value of sum.
Step 7: Stop the program.
Flowchart
Program:
x=float(input("Enter the value for x : "))
a=x
n=int(input("Enter the value for n : "))
x=x*3.14159/180
t=x;
sum=x
for i in range(1,n+1):
t=(t*(-1)*x*x)/(2*i*(2*i+1))
sum=sum+t;
print("The value of Sin(",a,")=",round(sum,2))
Result
Thus the sine series program has been executed and verified successfully.
Date: 1.D. Weight of a
Motorbike Aim
To write a python program to find the weight of a motorbike.
Algorithm
Step 1: Start the program
Step 2: Initialize values to the parts of the motorbike in weights(Chassis, Engine, Transmissions,
Wheels, Tyres, Body panels, Mud guards, Seat, Lights)
Step 3: Process the following weight = weight+sum_motorbike[i]
Step 4: Repeat the step 3, looping 'n’' times to get the sum of weight of the vehicle
Step 5: Display the Parts and Weights of the motor bike
Step 6: Display “Weight of
theMotorbike” Step 7: Stop the program.
Flowchart
Program
sum_motorbike = {"Chassis" : 28, "Engine" : 22, "Transmissions" : 18, "Wheels" : 30, "tyres" :
15, "Body_Panels" : 120, "Mudguards" : 6, "Seat" : 10, "lights": 10}
weight = 0
for i in sum_motorbike:
weight = weight+sum_motorbike[i]
print("Parts and weights of the Motorbike")
for i in sum_motorbike.items():
print(i)
print("\nWeight of the Motorbike is:",weight)
Result
Thus the weight of the motorbike program has been executed and verified successfully.
Date: 1.E. Weight of a steel
bar Aim
To write a python program to find the weight of a steel bar.
Algorithm
Weight of steel bar = (d2 /162)*length (Where d-diameter value in mm and length value in m)
Step 1: Start the program.
Step 2: Read the values of the variable d and length.
Step 4: Process the following weight=(d2 /162kg/m)*length
Step 5: Display the value of weight.
Step 6: Stop the program.
Flowchart
Program
d=int(input("Enter the diameter of the steel bar in milli meter: " ))
length=int(input("Enter the length of the steel bar in meter: " ))
weight=((d**2)/162)*length
print("Weight of steel bar in kg per meter :", round(weight,2))
Result
Thus the weight of the steel bar program has been executed and verified successfully.
Date: 1.F. Compute Electrical Current in Three Phase AC
Circuit Aim
To write a python program to compute the Electrical Current in Three Phase AC Circuit.
Algorithm
Step 1: Start the program
Step 2: Import math header file for finding the square root of
3 Step 3: Read the values of pf, I and V.
Step 4: Process the following:
Perform a three phase power calculation using the following formula: P=√3 * pf * I * V
Where pf - power factor, I - current, V - voltage and P – power
Step 5: Display “The result is
P”. Step 6: Stop the program.
Flowchart
Program
import math
pf=float(input("Enter the Power factor pf (lagging): " ))
I=float(input("Enter the Current I: " ))
V=float(input("Enter the Voltage V: " ))
P=[Link](3)*pf*I*V
print("Electrical Current in Three Phase AC Circuit :", round(P,3))
Result
Thus the Electrical Current in Three Phase AC Circuit program has been executed and verified
successfully.
EX - 02
PYTHON PROGRAMMING USING SIMPLE STATEMENTS AND
EXPRESSIONS
(Exchange the values of two variables, circulate the values of n variables,
Distance between two points).
Date: 2.A. Exchange the values of two
variables Aim
To write a python program to exchange the values of two variables.
Algorithm
Step 1: Start the program
Step 2: Read the values of two variables
Step 3: Print the values of the two variables before
swapping. Step 4: Process the following
Swapping of two variables using tuple assignment
operator. a,b=b,a
Step 5: Display the values of the two variables after swapping.
Step 6: Stop the program.
Program
#with temporary variable
print("Swapping two values")
a=int(input("Enter the value of A: "))
b=int(input("Enter the value of B: "))
print("Before Swapping\nA value is:",a,"B value
is:",b) c=a #with temporary variable
a=b
b=c
print("After Swapping\nA value is:",a,"B value is:",b)
#without temporary variable
print("Swapping two values")
a=int(input("Enter the value of A: "))
b=int(input("Enter the value of B: "))
print("Before Swapping\nA value is:",a,"B value
is:",b) a=a+b #without temporary variable
b=a-b
a=a-b
print("After Swapping\nA value is:",a,"B value is:",b)
#Tuple assignment
print("Swapping two values")
a=int(input("Enter the value of A: "))
b=int(input("Enter the value of B: "))
print("Before Swapping\nA value is:",a,"B value
is:",b) a,b=b,a #Tuple assignment
print("After Swapping\nA value is:",a,"B value is:",b)
Result
Thus the exchange the values of two variables program has been executed and verified
successfully.
Date: 2.B. Circulate the values of n
variables Aim
To write a python program to circulate the values of n variables
Algorithm
Step 1: Start the program
Step 2: Read the values of two variables
Step 3: Display the values of the two variables before swapping.
Step 4: Process the following
Swapping of two variables using tuple assignment
operator. a,b=b,a
Step 5: Display the values of the two variables after swapping.
Step 6: Stop the program.
Program
print("Circulate the values of n
variables") list1=[10,20,30,40,50]
print("The given list is: ",list1)
n=int(input("Enter how many circulations are required:
")) circular_list=list1[n:]+list1[:n]
print("After",n,"circulation is: ",circular_list)
Program
from collections import deque
lst=[1,2,3,4,5]
d=deque(lst)
print d
[Link](2)
print d
Result
Thus circulate the values of n variables program has been executed and verified successfully.
Date: 2.C. Distance between two points
Aim
To write a python program to find the distance between two points
Algorithm
Step 1: Start the program
Step 2: Read the values of two points (x1,y1,x2,y2)
Step 3: Process the following
Result=[Link](((x2-x1)**2)+((y2-y1)**2))
Step 4: Display the result of distance between two points.
Step 5: Stop the program.
Program
import math
print("Enter the values to find the distance between two
points") x1=int(input("Enter X1 value: "))
y1=int(input("Enter Y1 value: "))
x2=int(input("Enter X2 value: "))
y2=int(input("Enter Y2 value: "))
Result=[Link](((x2-x1)**2)+((y2-y1)**2))
print("Distance between two
points:",int(Result))
Result
Thus the distance between two points program has been executed and verified successfully.
EX – 03
SCIENTIFIC PROBLEMS USING CONDITIONALS AND ITERATIVE LOOPS
(Number series, Number Patterns, pyramid pattern)
Date: 3.A. Number Series
Aim
To write a python program for the Number Series
a. Fibonacci sequence: 0 1 1 2 3 5 8 13 21
34 Algorithm
Step 1: Start the program
Step 2: Read the number of terms n
Step 3: Initialize f1 = -1, f2 = 1
Step 4: Process the following from i=0 to n
times f3=f1+f2
Display f3
Do the tuple assignment f1,f2=f2,f3
Step 5: Stop the program.
Program
print("Program for Number Series : Fibanacci
Sequence") n=int(input("How many terms? "))
f1=-1
f2=1
for i in range(n):
f3=f1+f2
print(f3,end=" ")
f1,f2=f2,f3
b. Number Series: 12+22+…+n2
Algorithm
Step 1: Start the program
Step 2: Read the number of terms n
Step 3: Initialize sum=0
Step 4: Process the following from i=1 to n+1 times
Sum = sum + i**2
Step 5: Display sum
Step 6: Stop the program.
Program
print("Program for Number Series")
n=int(input("How many terms? "))
sum=0
for i in
range(1,n+1):
sum+=i**2
print("The sum of series = ",sum)
Result
Thus the number series program has been executed and verified successfully.
Date: 3.B. Number Patterns
Aim
To write a python program for the Number Patterns
a. Number Pattern_Type
1 Algorithm
Step 1: Start the program
Step 2: Read the number of rows
Step 3: Process the following from i=1 to rows+1 times
Step 3a: Process the following from j=0 to i
times
Display i
Step 4: Stop the program.
Program
print("Program for Number Pattern")
rows=int(input("Enter the number of rows: "))
for i in range(1,rows+1):
for j in range(0,i):
print(i,end=" ")
print(" ")
b. Number Pattern_Type
2 Algorithm
Step 1: Start the program
Step 2: Read the number of rows
Step 3: Process the following from i=1 to rows+1 times
Step 3a: Process the following from j=1 to i+1 times
Display j
Step 4: Stop the
program.
Program
b. Number Pattern
print("Program for Number Pattern")
rows=int(input("Enter the number of rows: "))
for i in range(1,rows+1):
for j in
range(1,i+1):
print(j,end=" ")
print(" ")
Result
Thus the number patterns programs have been executed and verified successfully.
Date: 3.C. Pyramid Patterns
Aim
To write a python program for the Pyramid Patterns
Algorithm
Step 1: Start the program
Step 2: Read the number of rows
Step 3: Process the following from i=1 to rows+1 times
Step 3a: Process the following from space=1 to(rows- i)+1 times
Display empty space
Step 3b: Process the following from j=0 to 2*i-1 times
Display ‘*’
Step 4: Stop the program.
Program
Pyramid pattern
rows = int(input("Enter number of rows: "))
for i in range(1, rows+1):
for space in range(1, (rows-i)+1):
print(end=" ")
for j in range(0,2*i-
1): print("* ",
end="")
print()
Result
Thus the pyramid pattern program has been executed and verified successfully.
EX – 04
IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS USING LISTS,
TUPLES
(Items present in a library/Components of a car/ Materials required for construction of a
building – operations of list & tuples)
Date: IMPLEMENTING REAL
TIME/TECHNICALAPPLICATIONS USING LISTS, TUPLES
Aim
To write a python program for the implementing real time/technical applications using lists,
tuples.
Items present in a library
Algorithm
Step 1: Start the program
Step 2: Initialize the Library list with the following items "Books","e-Books”,
"Journals","Audiobooks","Manuscripts","Maps","Prints","Periodicals",
"Newspapers"
Step 3: Process the following from i in
Library Display i
Step 4: Remove an item “Prints” from Library
list Step 5: Display all items from Library list
Step 6: Remove 4th index item from Library list
Step 7: Display all items from Library list
Step 8: Delete all items from Library
list Step 9: Display the Library list
Step 10: Add an item "CD’s" to the Library list
Step 11: Insert an item "DVD's" at index 0 to the Library
list Step 12: Display the Library list
Step 13: Display an index of "DVD's" from the Library list
Step 14: Using slice operator deletes an item at index 0 from the Library
list Step 12: Display the Library list
Step 13: Stop the program
Program
print("Welcome to Riya Advanced Library")
print(" ")
Library=["Books","e-
Books","Journals","Audiobooks","Manuscripts","Maps","Prints","Periodicals","Newspapers"]
for i in Library:
print(i)
print(" ")
print(Library)
[Link]("Prints")
print(Library)
[Link](4)
print(Library)
[Link]()
print(Library)
[Link]("CD’s")
print(Library)
[Link](0,"DVD's")
print(Library)
print([Link]("DVD's"))
del Library[0:1]
print(Library)
Components of a car
Program
print("Components of a
car") print(" ")
Main_parts=["Chassis","Engine","Auxiliaries"]
Transmission_System=["Clutch","Gearbox", "Differential","Axle"]
Body=["Steering system","Braking system"]
print("Main Parts of the Car:",Main_parts)
print("Transmission systems of the Car:",Transmission_System)
print("Body of the Car:",Body)
total_parts=[]
total_parts.extend(Main_parts)
total_parts.extend(Transmission_System)
total_parts.extend(Body)
print(" ")
print("Total components of the
car:",len(total_parts)) print(" ")
total_parts.sort()
j=0
for i in total_parts:
j=j+1
print(j,i)
Materials required for construction of a building
Program
print("Materials required for construction of a building")
print("Approximate Price: \[Link]%\[Link]%\[Link]%\[Link]
bars:24%\[Link]%\[Link]%\[Link]%\[Link] items:5%\[Link]
items:5%\[Link] products:10%\[Link] accessories:3%")
materials=("Cement/Bag","Sand/Cubic feet","Aggregates/Cubic feet","Steel
bars/Kilogram","Bricks/Piece","Paints/Litres","Tiles/Squre feet","Plumbing items/meter or
piece","Electrical items/meter or piece", "Wooden products/square feet", "Bathroom
accessories/piece")
price=[410,50,25,57,7,375,55,500,500,1000,1000]
for i in range(len(materials)):
print(materials[i],":",price[i])
print(" ")
#materials[0]="Glass items" -tuple is immutable
price[0]=500
for i in range(len(materials)):
print(materials[i],":",price[i])
print(" ")
print("Operations of tuple/list")
print(min(price))
print(max(price))
print(len(price))
print(sum(price))
print(sorted(price))
print(all(price))
print(any(price))
Result
Thus the python program has been executed and verified successfully.
Ex - 05
IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS
USING SETS, DICTIONARIES
(Language, Components of an automobile, Elements of a civil structure, etc, operations of
Sets & Dictionaries)
DATE: IMPLEMENTING REAL-TIME/TECHNICAL
APPLICATIONS USING SETS, DICTIONARIES
Language
Program
LANGUAGE1 = {'Pitch', 'Syllabus', 'Script', 'Grammar', 'Sentences'};
LANGUAGE2 = {'Grammar', 'Syllabus', 'Context', 'Words',
'Phonetics'}; # set union
print("Union of LANGUAGE1 and LANGUAGE2 is ",LANGUAGE1 | LANGUAGE2)
# set intersection
print("Intersection of LANGUAGE1 and LANGUAGE2 is ",LANGUAGE1 &
LANGUAGE2)
# set difference
print("Difference of LANGUAGE1 and LANGUAGE2 is ",LANGUAGE1 - LANGUAGE2)
print("Difference of LANGUAGE1 and LANGUAGE2 is ",LANGUAGE2 - LANGUAGE1)
# set symmetric difference
print("Symmetric difference of LANGUAGE1 and LANGUAGE2 is ",LANGUAGE1 ^
LANGUAGE2)
Components of an automobile
Program
print("Components of an automobile")
print("\n")
print("Dictionary keys")
print(" ")
components={"Engine parts":["piston","cylinder head","oil pan","engine valves","combustion
chamber","gasket"],"Drive transmission and steering parts":["Adjusting nut","pitman arm
shaft","roller bearing","steering gear shaft"],"Suspension and brake parts":["Break pedal","Brake
lines","Rotors/drums","Break pads","Wheel cylinders"],"Electrical parts":
["Battery","Starter","Alternator","Cables"],"Body and chassis":["Roof panel","front panel","screen
pillar","Lights","Tyres"]}
for i in [Link]():
print(i)
print("\n")
print("Dictionary values")
print(" ")
for i in [Link]():
print(i)
print("\n")
print("Dictionary items")
print(" ")
for i in [Link]():
print(i)
print("\n")
accessories={"Bumper":["front","back"]}
[Link](accessories)
components['Bumper']=["front and back"]
print("Dictionary items")
print(" ")
for i in [Link]():
print(i)
print("\n")
print(len(components))
del components["Bumper"]
[Link]("Electrical parts")
[Link]()
print("\n")
print("Dictionary items")
print(" ")
for i in [Link]():
print(i)
[Link]();
print(components)
Elements of a civil structure
Program
print("Elements of a civil
structure") print(" ")
print("[Link] \[Link] \[Link] \[Link] and slabs \[Link] \[Link]
\[Link]\[Link]\[Link]\[Link] proof")
elements1={"foundation","floors","floors","walls","beams and
slabs","columns","roof","stairs","parapet","lintels"} print("\
n")
print(elements1)
print("\n")
[Link]("damp proof") #add
print(elements1)
elements2={"plants","compound"}
print("\n")
print(elements2)
print("\n")
[Link](elements2) #extending
print(elements1)
[Link]("stairs") #data removed, if item not present raise error
print(elements1)
[Link]("hard floor") #data removed,if item not present not raise error
print(elements1)
[Link]()
print(elements1)
print(sorted(elements1))
print("\n")
print("set operations")
s1={"foundation","floors"}
s2={"floors","walls","beams"}
print(s1.symmetric_difference(s2))
print([Link](s2))
print([Link](s1))
print([Link](s2))
print([Link](s2))
Result
Thus the python program has been executed and verified successfully.
EX - 06
IMPLEMENTING PROGRAMS USING FUNCTIONS.
(Factorial, largest number in a list, area of shape)
DATE: IMPLEMENTING PROGRAMS USING FUNCTIONS.
Factorial
Program
def factorial(num): #function
definition fact=1
for i in range(1,num+1):
fact=fact*i
return fact
number=int(input("Please enter any number to find the factorial:"))
result=factorial(number) #function calling
print("Using functions - The factorial of %d = %d" %(number,result))
Largest number in a list
Program
def myMax(list1):
maxi = list1[0]
for x in list1:
if(x>maxi):
maxi=x
return maxi
list1 = [100, 200, 500, 150, 199, 487]
print("Largest element in the list is:", myMax(list1))
def myMax(list1):
maxi = list1[0]
for x in list1:
if(x>maxi):
maxi=x
return maxi
list1 = [100, 200, 500, 150, 199, 487]
print("Largest element in the list is:", myMax(list1))
Area of shape
Program
def calculate_area(name):
name=[Link]()
if name == "rectangle":
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth:
"))
# calculate area of rectangle
rect_area = l * b
print(f"The area of rectangle is {rect_area}.")
elif name == "square":
s = int(input("Enter square's side length: "))
# calculate area of square
sqt_area = s * s
print(f"The area of square is {sqt_area}.")
elif name == "triangle":
h = int(input("Enter triangle's height length: "))
b = int(input("Enter triangle's breadth length:
"))
# calculate area of
triangle tri_area = 0.5 * b
*h
print(f"The area of triangle is {tri_area}.")
elif name == "circle":
r = int(input("Enter circle's radius length:
")) pi = 3.14
# calculate area of
circle circ_area = pi * r
*r
print(f"The area of circle is {circ_area}.")
elif name == 'parallelogram':
b = int(input("Enter parallelogram's base length: "))
h = int(input("Enter parallelogram's height length:
"))
# calculate area of
parallelogram para_area = b * h
print(f"The area of parallelogram is {para_area}.")
else:
print("Sorry! This shape is not available")
print("Calculate Shape Area:\nRectangle\nSquare\nTriangle\nCircle\nParallelogram")
shape_name=input("Enter the name of shape whose area you want to find: ")
calculate_area(shape_name)
Result
Thus the python program has been executed and verified successfully.
EX - 07
IMPLEMENTING PROGRAMS USING STRINGS
(Reverse, palindrome, character count, replacing characters)
DATE: IMPLEMENTING PROGRAMS USING STRINGS
String reverse
Program
def rev(string):
string="".join(reversed(string))
return string
s=input("Enter any string:")
print("The Original String
is:",end="") print(s)
print("The reversed string (using reversed function)
is:",end="") print(rev(s))
Palindrome
Program
string=input("Enter the string:")
string=[Link]()
print(string)
rev_string=reversed(string)
if(list(string)==list(rev_string)):
print(f"Given string {string} is
Palindrome.") else:
print(f"Given string {string} is not Palindrome.")
Character count
Program
string=input("Enter the string:")
print("Total characters in the given string is",len(string))
char=input("Enter a character to count:")
val=[Link](char)
print(val,"\n")
Replacing characters
Program
string=input("Enter the string:")
str1=input("Enter old string:")
str2=input("Enter replacable string:")
print([Link](str1,str2))
Result
Thus the python program has been executed and verified successfully.
EX - 08
IMPLEMENTING PROGRAMS USING WRITTEN MODULES AND PYTHON
STANDARD LIBRARIES
(numpy, pandas, Matplotlib, scipy)
DATE: IMPLEMENTING PROGRAMS USING WRITTEN MODULES
AND PYTHON
STANDARD LIBRARIES
Numpy
Program
#1D array
import numpy as np
arr=[Link]([10,20,30,40,50])
print("1 D array:\n",arr)
print(" ")
#2D array (matrix)
import numpy as
np
arr = [Link]([[1,2,3], [4,5,6]])
print("\n2 D array:\n",arr)
print("\n2nd element on 1st row is: ",
arr[0,1]) print(" ")
#3D array
(matrices) import
numpy as np
arr = [Link]([[[1,2,3], [4,5,6]], [[1,2,3], [4,5,6]]])
print("\n3 D array:\n",arr)
print("\n3rd element on 2nd row of the 1st matrix is",arr[0,1,2])
Pandas
Program
import pandas
mydata=['a','b','c','d','e']
myvar=[Link](mydata)
print(myvar)
print("\n")
mydataset={'cars':["BMW","Volvo","Ford"], 'passings':[3,7,2]}
print(mydataset)
myvar=[Link](mydataset)
print(myvar)
Scipy
from scipy import constants
print([Link])
print([Link])
print([Link])
print([Link])
print([Link])
print(constants.Julian_year)
print([Link]) #printing the kilometer unit (in meters)
print([Link]) #printing the gram unit (in kilograms)
print([Link]) #printing the miles-per-hour unit (in meters per seconds)
print([Link])
Program
import numpy as np
from scipy import io as
sio array = [Link]((4, 4))
[Link]('[Link]', {'ar': array})
data = [Link]("[Link]", struct_as_record=True)
data['ar']
Matplotlib
import [Link] as plt
import numpy as np
[Link]([-1,-4.5,16,23])
[Link]()
[Link]([10,200,10,200,10,200,10,200])
[Link]()
xpoints=[Link]([0,6])
ypoints=[Link]([0,250])
[Link](xpoints,ypoints)
[Link]()
Program
from scipy import misc
from matplotlib import pyplot as plt
import numpy as np
#get face image of panda from misc package
panda = [Link]()
#plot or show image of face
[Link]( panda )
[Link]()
Result
Thus the python program has been executed and verified successfully.
EX - 09
IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS
USING FILE HANDLING
(copy from one file to another, word count, longest word)
DATE: IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS
USING FILE HANDLING
Copy from one file to another
from shutil import copyfile
sourcefile = input("Enter source file name: ")
destinationfile = input("Enter destination file name: ")
copyfile(sourcefile, destinationfile)
print("File copied successfully!")
c = open(destinationfile, "r")
print([Link]())
[Link]()
Word count
file=open("[Link]","r")
data=[Link]()
words=[Link]()
print("Number of words in text file:",len(words))
Longest word
def longest_word(filename):
with open(filename,"r")as
infile:
words=[Link]().split()
max_len=len(max(words,key=len))
return [word for word in words if
len(word)==max_len] file_name=input("Enter the file
name:") print(longest_word(file_name))
Result
Thus the python program has been executed and verified successfully.
EX - 10
IMPLEMENTING REAL-TIME/TECHNICAL APPLICATIONS USING
EXCEPTION HANDLING
(Divide by zero error, voter’s age validity, student mark range validation)
DATE: IMPLEMENTING REAL-TIME/TECHNICAL
APPLICATIONS USING EXCEPTION HANDLING
Divide by zero error
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of
b:")) try:
c=a/b
print("Divide a / b:",c)
except ZeroDivisionError:
print("Found Divide by Zero Error!")
Voter’s age validity
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(err)
finally:
print("Thank you")
Student mark range validation
try:
python=int(input("Enter marks of the Python subject:
")) print("Python Subject Grade",end=" ")
if(python>=90):
print("Grade: O")
elif(python>=80 and python<90):
print("Grade: A+")
elif(python>=70 and python<80):
print("Grade: A")
elif(python>=60 and python<70):
print("Grade: B+")
elif(python>=50 and python<60):
print("Grade: B")
else:
print("Grade: U")
except:
print("Entered data is wrong, Try
Again") finally:
print("Thank you")
Result
Thus the python program has been executed and verified successfully.