Python Programming_Lab(23) (1)
Python Programming_Lab(23) (1)
To evolve as a centre of excellence for nurturing computer professionals with research and innovation
skills, inculcating moral values and societal concerns.
MISSION
M1: To transform students into creative computer engineers to meet global challenges.
M2: To produce competent and quality professionals by imparting computer concepts and techniques
and a zest for research and higher studies.
M3: To build entrepreneur skills and leadership qualities in the students by inculcating the spirit of
ethical values.
PEO 1: To excel in their career as competent software engineer in IT and allied organizations with
enriched curriculum and pedagogical initiatives.
PEO 2: To pursue higher education and to demonstrate research temper for providing solutions to
engineering problems
PEO 3: To contribute for the societal development and engage in lifelong learning by exhibiting
leadership, through professional, social and ethical values.
B)Createadictionaryandapplythefollowingmethods
2 1)Printthedictionaryitems2)accessitems3)useget()
4)changevalues5)use len()
C)Createatupleandperformthefollowingmethods
3
1)Additems2)len()3)checkforitemintuple4)Accessiems
1 A)Writeapythonprogramtoaddtwonumbers.
B)Writeapythonprogramtocheckwhetherthegivenstringis
2 palindromeornot.
1 A)Writeaprogramtodoubleagivennumberand
addtwonumbersusinglambda()?
2 B) Writeaprogramfor filter()to filter onlyeven numbers
from a given list.
C) Write a program formap() function to double all
3
the items in the list?
D)Write aprogram to findsum of the numbersfor the
4
elements of the listbyusing reduce()?
A) Demonstrate a python code to
1
implementabnormal termination?
B) Demonstrateapythoncodetoprinttry, except and
2
finallyblock statements
C)Writeapython programtoopenandwrite“hello world”
3
into a file?
D)Writea pythonprogramtowritethecontent “hi python
4
programming” for the existing file.
1 A)Writeapythonprogramtogetpythonversion.
B) Write apythonprogram to open afile andcheckwhat are the
2 access permissions acquired by thatfile
usingos module?
createstaffandstudentfunctiontomodule?
C)Usinganumpymodulecreatearrayandcheckthefollowing:
1. Reshape 3X4 arrayto 2X2X3 array2. Sequence ofintegers
3 from 0 to 30 with steps of 5
3.Flattenarray 4.Constantvaluearray ofcomplex Type
B)Writeapythoncodetosetbackgroundcolorandpicand draw a
2 square and fill the color using turtle module
Aim:
A) Createalistandperformthefollowingmethods
1) insert()2)remove() 3)append()4)len()5)pop()6)clear()
Program:
a=[1,3,5,6,7,[3,4,5],"hello"]
print(a)
a.insert(3,20)
print(a)
a.remove(7)
print(a)
a.append("hi")
print(a)
len(a)
print(a)
a.pop()
print(a)
a.pop(6)
print(a)
a.clear()
print(a)
Output:
PROGRAM-2
Program:
a=int(input("enterthevaluefora"))
b=int(input("enterthevaluefora"))
c=a+b
print("Thesumofaandbis",c)
Output:
PROGRAM-3
Aim:
1. TOPERFORMADDITITON2.TOPERFORM SUBTRACTION
3.TOPERFORMMULTIPICATION4. TOPERFORMDIVISION
Acceptsusersinputandperformtheoperationaccordingly.Usefunctionswitharguments.
Program:
defadd(a,d):
return a+b
defsub(c,d):
return c-d
defmul(e,f):
return b*h
defdiv(g,h):
return s/s
print("=================")
print("1.TOPERFORMADDITITON")
print("3.TOPERFORMMULTIPICATION")
print("=================")
choice=int(input("EnterYourchoice")) if
choice ==1:
a=int(input("Enter the 1st value"))
b=int(input("Enterthe2ndvalue"))
print(add(a,b))
elifchoice==2:
d=int(input("Enterthe2ndvalue"))
print(sub(c,d))
elifchoice==3:
f=int(input("Enterthe2ndvalue"))
print(mul(e,f))
elifchoice==4:
h=int(input("Enterthe2ndvalue"))
print(areadOfSquare(s))
else:
print("wrongchoice")
PROGRAM-4
Aim:
A) Write a program to double a given number and add two numbers using lambda()?
Program:
double=lambdax:2*x
print(double(5))
add=lambdax,y:x+y
print(add(5,4))
PROGRAM-5
Aim:
A) Demonstrate a python code to implement abnormal termination?
Program:
a=5
b=0
print(a/b)
print("bye")
PROGRAM-6
Aim:
A) Write a python program to get python version.
Program:
Import sys
print("System version is:")
print(sys.version)print("Version
Information is:")
print(sys.version_info)
PROGRAM-7
Write a python program to print date, time for today and now.
Program:
import datetime
a=datetime.datetime.today()
b=datetime.datetime.now()
print(a)
print(b)
PROGRAM-8
Aim:
Program:
defadmin():
print("hi")
def cabin():
print("hello")
PROGRAM-9
Aim:
A) WriteapythonProgramtodisplaywelcometoMRCETbyusingclassesandobjects.
Program:
classdisplay:
def displayMethod(self):
print("welcometomrcet")
#object creation process
obj = display()
obj.displayMethod(
PROGRAM-10
Aim:
A) Usinganumpymodule createanarrayandcheckthefollowing:
1. Typeofarray2.Axes ofarray
3.Shapeofarray4.Type ofelementsinarray
Program:
import numpy as np
arr=np.array([[1,2,3],[4,2,5]])
print("Array is of type:",type(arr))
print("no.ofdimensions:",arr.ndim)
print("Shape of array:",arr.shape)
print("Size of array:",arr.size)
print("Arraystoreselementsoftype:",arr.dtype
PROGRAM-11
Aim:
A) Writeapythonprogramtoconcatenatethedataframeswithtwo differentobjects.
Program:
import pandas as pd
one=pd.DataFrame({'Name':['teju','gouri'],
'age':[19,20]},
index=[1,2])
two=pd.DataFrame({'Name':['suma','nammu'],
'age':[20,21]},
index=[3,4])
print(pd.concat([one,two]))
PROGRAM-12
Aim:
A) Writeapythoncodetosetbackgroundcolor andpicanddrawacircleusingturtlemodule
Program:
import turtle
t=turtle.Turtle()
t.circle(50)
s=turtle.Screen()
s.bgcolor("pink")
s.bgpic("pic.gif")