Python Lab Programs
Python Lab Programs
PROGRAM:
l1=[]
for i in l:
if i not in l1:
l1.append(i)
for i in l1:
print(i,end=' ')
OUTPUT:
PROGRAM:
t=(n,m,res,a)
OUTPUT
N KAVYA
3. Implement python script to perform union, Intersection, Difference
PROGRAM:
OUTPUT :
N KAVYA
4. Define a function, which generates Fibonacci series up to n numbers.
PROGRAM:
def fib(n):
if n==0 or n==1:
return n
return fib(n-1)+fib(n-2)
for i in range(n):
f=fib(i)
print(f,end=' ')
OUTPUT
recursion.
PROGRAM:
def fact(n):
if n==0:
return 1
return n*fact(n-1)
f=fact(n)
N KAVYA
OUTPUT
exception-handling mechanism.
PROGRAM:
try:
except ZeroDivisionError:
")
except ValueError:
else:
try:
finally:
N KAVYA
print(" Possible Arithmetic operations completed ")
OUTPUT :
or not.
PROGRAM:
53
s1=s[::-1]
if s==s1:
else:
OUTPUT:
N KAVYA
8.Write a python script to Create &access class variables and methods
Program:
class Robot:
population=0
what="Humanoid Robot"
version=1.0
speed="1THZ"
memory="1ZB"
self.name = name
Robot.population += 1
def _del_(self):
Robot.population -= 1
if Robot.population == 0:
N KAVYA
print(self.name ,' was the last one.')
else:
def update(cls):
cls.version=2.0
cls.speed = "2THZ"
cls.memory="2ZB"
def sayHi(self):
print("\nHai i am a : ",self.what)
print("Version : ",self.version)
print("Speed : ",self.speed)
print("Memory : ",self.memory)
def howMany():
d=Robot('Chitti')
d.sayHi()
Robot.howMany()
d1=Robot('Vennela')
d1.update()
d1.sayHi()
Robot.howMany()
del d
del d1
Robot.howMany()
N KAVYA
Output:
Program:
61
@dispatch(int,int)
def product(first,second):
result = first*second
@dispatch(int,int,int)
def product(first,second,third):
N KAVYA
result = first * second * third
@dispatch(float,float,float)
def product(first,second,third):
product(2,3)
product(2,3,2)
product(2.2,3.4,2.3)
Output
Program:
62
class Parent:
def __init__(self,fname,fage):
self.firstname=fname
self.age=fage
def view(self):
print(self.firstname , self.age)
class Child(Parent):
N KAVYA
Parent.__init__(self, fname, fage)
self.lastname="Internet"
def view(self):
python")
ob = Child("Python" , '28')
ob.view()
Output:
11. Implement python script to print all the prime numbers with in the
given range
PROGRAM:
n1=int(n1)
n2=int(n2)
for n in range(n1,n2+1):
flag=1
for i in range(2,n//2+1):
r=n%i
if(r==0):
flag=0
N KAVYA
break
if flag==1:
OUTPUT
palindrome or not
PROGRAM:
rev=0
m=n
while n!=0:
r=n%10
rev=rev*10+r
n=n//10
if rev==m:
else:
OUTPUT:
N KAVYA
13.Implement python script to sort a tuple by its float element.
PROGRAM:
26
l=[]
for i in range(n):
t=tuple(input().split())
l.append(t)
OUTPUT:
N KAVYA
create new one.
dic3={5:50,6:60}
PROGRAM:
d1={1:10, 2:20}
d2={3:30, 4:40}
d3={5:50, 6:60}
d={}
for i in (d1,d2,d3):
d.update(i)
OUTPUT
Program:
class Bank:
def getroi(self):
return 10
N KAVYA
63
class SBI(Bank):
def getroi(self):
return 7
class ICICI(Bank):
def getroi(self):
return 8
class Axis(Bank):
def display(self):
b1 = Bank()
b2 = SBI()
b3 = ICICI()
b4 = Axis()
b4.display()
Output:
N KAVYA