py PDF hh
py PDF hh
NO: 1(a)
LIST FUNCTIONS
DATE:
AIM:
ALGORITHM:
my_list=['p','r','o','b','l','e','m']
print(my_list)
my_list.remove('p')
print(my_list)
1
PROGRAM CODE:
my_list=['p','r','o','b','l','e','m']
print(my_list)
my_list.remove('p')
print(my_list)
print(my_list.pop(1))
print(my_list)
print(my_list.pop())
print(my_list)
my_list.append('abi')
print(my_list)
my_list=[1,2,3,6,5,9,4]
my_list.insert(3,'abi')
print(my_list)
print my_list.count(2)
my_list.sort()
print(my_list)
my_list.reverse()
print(my_list)
2
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified.
3
EX.NO: 1(b)
TUPLE FUNCTIONS
DATE:
AIM:
ALGORITHM:
t5=(10,20,30,40,50)
print(max(t5))
print(min(t5))
4
PROGRAM CODE:
my_tuple=()
print(my_tuple)
my_tuple=(10,20,30)
print(my_tuple)
my_tuple=(10,"hello",20,30)
print(my_tuple)
my_list=("mouse",[8,6,5,9],(1,2,3))
print(my_tuple)
my_tuple=3,4,6,"abi"
print(my_tuple)
t1=('monday','tuesday')
t3=my_tuple+t1
print(t3)
t4=len(t3)
print(t4)
t5=(10,20,30,40,50)
print(max(t5))
print(min(t5))
colors=('red','yellow','orange')
fruits=('apple','orange','mango')
quantity=('1kg','2kg','3kg')
print (list(zip(colors,fruits,quantity)))
a,b,c,=my_tuple
print(a)
print(b)
print(c), print(d)
5
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified.
6
EX.NO: 1(c)
DICTIONARY FUNCTIONS
DATE:
AIM:
ALGORITHM:
t5=(10,20,30,40,50)
print(max(t5))
print(min(t5))
7
PROGRAM CODE:
country_capitals = {
"Italy": "Rome",
"England": "London"
print(country_capitals)
print(len(country_capitals))
print(country_capitals["United States"])
print(country_capitals["England"])
country_capitals["Italy"] = "Rome"
print(country_capitals)
country_capitals["Germany"] = "Berlin"
print(country_capitals)
print(country_capitals)
8
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
9
EX.NO: 2(a)
TEMPERATURE CONVERSION
DATE:
AIM:
ALGORITHM:
cel=(f-32)/1.8
fah=(c*1.8)+32
10
PROGRAM CODE:
print("~~~~~TEMPERATURE CONVERSION~~~~~~~")
print("Select Operation")
if ch==1:
f=float(fah)
cel=(f-32)/1.8
elif ch==2:
c=float(cel)
fah=(c*1.8)+32
else:
print("INVALID INPUT")
11
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
12
EX.NO: 2(b)
STUDENT MARKSHEET CREATION
DATE:
AIM:
ALGORITHM:
Step 4: declare a variable sub1,sub2,sub3 for get input from the user.
tot=sub1+sub2+sub3
avg=tot/3
13
PROGRAM CODE:
tot=sub1+sub2+sub3
avg=tot/3
if (avg>=80):
print("A grade")
print("B grade")
print("C grade")
print("D grade")
else:
print("E grade")
14
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
15
EX.NO: 3(a)
SUM OF NATURAL NUMBERS
DATE:
AIM:
ALGORITHM:
Step 4: declare a variable num for get input from the user.
num=int(input("Upto Which Numbers??"))
if num<0:
exit()
16
PROGRAM CODE:
print("\t\t~*~*~*~*~*\tSUM OF NATURAL NUMBERS\t~*~*~*~*~*~*")
if num<0:
exit()
elif num<1:
else:
sum=0
while num>0:
sum+=num
num-=1
17
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
18
EX.NO: 3(b)
PRIME NUMBER GENERATION
DATE:
AIM:
ALGORITHM:
Step 4: declare a variables low,high value for get input from the user.
for number in range(lower_value,high_value+1):
if number>1:
for i in range(2,number):
if(number%i)==0:
19
PROGRAM CODE:
lower_value=int(input(" Please Enter the lowest limit:"))
if number>1:
for i in range(2,number):
if(number%i)==0:
break
else:
print(number)
20
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
21
EX.NO: 4(a)
AREA CALCULATION
DATE:
AIM:
ALGORITHM:
def areaSquare(side)
def areaCircle(rad)
22
PROGRAM CODE:
def areaRectangle(length,breath):
area=length*breath
return area
def areaSquare(side):
area=areaRectangle(side,side)
return area
def areaCircle(rad):
radius=3.14*rad*rad
return radius
def areaTriangle(a,b,c):
s=(a+b+c)/2;
area=(s*(s-a)*(s-b)*(s-c))**0.5
return area
def main():
print("\t\t***************************************************")
print("\t\t***************************************************")
lengthRect=int(input('length:'))
breathRect=int(input('breath:'))
areaRect=areaRectangle(lengthRect,breathRect)
areaSqr=areaSquare(sideSqr)
23
areacir=areaCircle(radius1)
areaTri=areaTriangle(side1,side2,side3)
24
OUTPUT
RESULT:
Thus the given program has been executed successfully and output was verified
25
EX.NO: 4(b)
FACTORIAL USING RECURSION
DATE:
AIM:
ALGORITHM:
def recur_factorial(n):
if n==1:
return n
else:
return n*recur_factorial(n-1)
26
PROGRAM CODE:
def recur_factorial(n):
if n==1:
return n
else:
return n*recur_factorial(n-1)
num=7
if num<0:
elif num==0:
else:
27
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
28
EX.NO: 5
EXCEPTION HANDLING
DATE:
AIM:
ALGORITHM:
29
PROGRAM CODE:
import sys
def main():
try:
price=float(price)
weight=float(weight)
result=price/weight
except ValueError:
except TypeError:
except ZeroDivisionError:
except:
print(str(sys.exc_info()))
else:
30
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
31
EX.NO: 6(a)
MULTIPLE INHERITANCE
DATE:
AIM:
ALGORITHM:
def __init__(self):
self.univ="MKU"
def display(self):
32
PROGRAM CODE:
class university:
def __init__(self):
self.univ="MKU"
def display(self):
class course(university):
def __init__(self):
university.__init__(self)
self.course="BSC"
def display(self):
university.display(self)
class branch(university):
def __init__(self):
self.branch="PYTHON"
def display(self):
class student(course,branch):
def __init__(self):
33
self.name="ABI"
branch.__init__(self)
course.__init__(self)
def display(self):
branch.display(self)
course.display(self)
ob=student()
print()
ob.display()
34
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
35
EX.NO: 6(b)
MULTILEVEL INHERITANCE
DATE:
AIM:
ALGORITHM:
def getdata(self):
self.__name=input("enter name:")
self.__sal=int(input("enter salary:"))
36
PROGRAM CODE:
class Student:
def getStudentInfo(self):
self.__name=input("enter name:")
def printStudentInfo(self):
class Bsc(Student):
def getBsc(self):
self.getStudentInfo()
def printBsc(self):
self.printStudentInfo()
def calcTotalMarks(self):
return(self.__p+self.__m+self.__c)
class Result(Bsc):
def getResult(self):
self.getBsc()
self.__total=self.calcTotalMarks()
def putResult(self):
self.printBsc()
S=Result()
S.getResult(),S.putResult(
37
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
38
EX.NO: 6(c)
HIERARICAL INHERITANCE
DATE:
AIM:
ALGORITHM:
def __init__(self):
self.__id="<no id>"
self.__name="<no name>"
self.__gender="<no gender>"
39
PROGRAM CODE:
class details:
def __init__(self):
self.__id="<no id>"
self.__name="<no name>"
self.__gender="<no gender>"
def setdata(self,id,name,gender):
self.__id=id
self.__name=name
self.__gender=gender
def showdata(self):
print("id:",self.__id)
print("name:",self.__name)
print("gender:",self.__gender)
class employee(details):
def __init__(self):
self.__company="<no company>"
self.__dept="<no dept>"
def setemployee(self,id,name,gender,comp,dept):
self.setdata(id,name,gender)
self.__company=comp
self.__dept=dept
def showemployee(self):
self.showdata()
print("company:",self.__company)
print("department:",self.__dept)
40
class doctor(details):
def __init__(self):
self.__hospital="<no hospital>"
self.__dept="<no dept>"
def setemployee(self,id,name,gender,hos,dept):
self.setdata(id,name,gender)
self.__hospital=hos
self.__dept=dept
def showemployee(self):
self.showdata()
print("hospital:",self.__hospital)
print("department:",self.__dept)
def main():
print("employee object")
e=employee()
e.setemployee(1,"prem sharma","male","gmr","excavation")
e.showemployee()
d=doctor()
d.setemployee(1,"pankaj","male","aiims","eyes")
d.showemployee()
41
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
42
EX.NO: 6(d)
HYBRID INHERITANCE
DATE:
AIM:
ALGORITHM:
def __init__(self):
self.__id="<no id>"
self.__name="<no name>"
self.__gender="<no gender>"
43
PROGRAM CODE:
class university:
def __init__(self):
self.univ="MKU,TKS COLLEGE"
def display(self):
class course(university):
def __init__(self):
university.__init__(self)
self.course="Bsc.COMPUTER SCIENCE"
def display(self):
university.display(self)
class branch(university):
def __init__(self):
self.branch="OOPS"
def display(self):
class student(course,branch):
def __init__(self):
44
self.name="MSP"
branch.__init__(self)
course.__init__(self)
def display(self):
branch.display(self)
course.display(self)
ob=student()
print()
ob.display()
45
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
46
EX.NO: 7
POLYMORPHISM
DATE:
AIM:
ALGORITHM:
self.name = name
self.age = age
47
PROGRAM CODE:
class Cat:
self.name = name
self.age = age
def info(self):
def make_sound(self):
print("Meow")
class Dog:
self.name = name
self.age = age
def info(self):
def make_sound(self):
print("Bark")
dog1 = Dog("Fluffy", 4)
animal.make_sound()
animal.info()
animal.make_sound()
48
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
49
EX.NO: 8
FILES OPERATIONS
DATE:
AIM:
ALGORITHM:
outfile=open('myfile.txt','w')
while True:
line=input('enter line:')
line +='\n'
outfile.write(line)
50
PROGRAM CODE:
def writelines():
outfile=open('myfile.txt','w')
while True:
line=input('enter line:')
line +='\n'
outfile.write(line)
if choice=='n':
break
outfile.close()
writelines()
def count_word():
file = open('myfile.txt','r')
count = 0
words = line.split()
if word == 'country':
count +=1
print(count)
file.close()
count_word()
51
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified.
52
EX.NO: 9
MODULES
DATE:
AIM:
ALGORITHM:
53
PROGRAM CODE:
#Code in my.py
def large(a,b):
if a<b:
return a
else:
return b
#code in find.py
import my
print("large(50,100)==>",my.large(50,100))
print("large(B,C)==>",my.large('B','C'))
print("large(Hi,BI)==>",my.large('HI','BI'))
54
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
55
EX.NO: 10
CREATING DYNAMIC AND INTERACTIVE WEBPAGES
DATE:
USING FORMS
AIM:
ALGORITHM:
Step 3: First install the pip flask in python & configure the flask.
scripts path.
Step 6: Then open command prompt to type flask run command and
copy the linkaddress to paste the browser.
Step 7: Save and run the program.
56
PROGRAM CODE:
App.py code:
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Interactive Web Page</title>
</head>
<body>
<h1>Interactive Web Page</h1>
<form method="POST">
<label for="username">Enter your name:</label>
<input type="text" id="username" name="username" required>
<input type=”submit” value=”Submit”>
</form>
</body>
</html>
57
OUTPUT:
RESULT:
Thus the given program has been executed successfully and output was verified
58