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

py PDF hh

Uploaded by

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

py PDF hh

Uploaded by

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

EX.

NO: 1(a)

LIST FUNCTIONS
DATE:

AIM:

To write a program for perform list functions using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: Create a list and perform the fuctions of list.

my_list=['p','r','o','b','l','e','m']

print(my_list)

my_list.remove('p')

print(my_list)

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

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:

To write a program for perform tuple fucntions using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: Create a tuple and perform the fuctions of tuple.

t5=(10,20,30,40,50)

print(max(t5))

print(min(t5))

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

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:

To write a program for perform tuple fucntions using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: Create a dictionary and perform the fuctions of dictionary.

t5=(10,20,30,40,50)

print(max(t5))

print(min(t5))

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

7
PROGRAM CODE:

country_capitals = {

"United States": "Washington D.C.",

"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)

del country_capitals["United States"]

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:

To write a program for perform temperature conversion using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a variable ch for get input from the user.

cel=(f-32)/1.8

fah=(c*1.8)+32

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

10
PROGRAM CODE:
print("~~~~~TEMPERATURE CONVERSION~~~~~~~")

print("Select Operation")

print ("1.fahren to cel")

print ("2.cel to fahren")

ch=int(input("Enter Your Choice to Convert:--->"))

if ch==1:

fah=input("Enter The Temperature In Fahrenheit:-->")

f=float(fah)

cel=(f-32)/1.8

print("Temperature In celsius Is:%.2f"%cel+chr(176))

elif ch==2:

cel=input("Enter The Temperature In Celsius:-->")

c=float(cel)

fah=(c*1.8)+32

print("Temperature In Fahernheit Is:%.2f"%fah+chr(176))

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:

To write a program for perform temperature conversion using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a variable sub1,sub2,sub3 for get input from the user.
tot=sub1+sub2+sub3

avg=tot/3

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program

13
PROGRAM CODE:

print("***** STUDENT MARKLIST USING ELSE.....IF*****")

sub1=int(input("Enter Marks Of The First Subject:"))

sub2=int(input("Enter Marks Of The Second Subject:"))

sub3=int(input("Enter Marks Of The Third Subject:"))

tot=sub1+sub2+sub3

avg=tot/3

print("Total Mark Is:%2.f"%tot)

print("Average Mark Is:%.2f"%avg)

if (avg>=80):

print("A grade")

elif (avg>=70 and avg<80):

print("B grade")

elif (avg>=60 and avg<70):

print("C grade")

elif (avg>=40 and avg<60):

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:

To write a program for perform sum of natural number using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a variable num for get input from the user.
num=int(input("Upto Which Numbers??"))

if num<0:

exit()

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program

16
PROGRAM CODE:
print("\t\t~*~*~*~*~*\tSUM OF NATURAL NUMBERS\t~*~*~*~*~*~*")

print("Enter '0' to Exist")

num=int(input("Upto Which Numbers??"))

if num<0:

exit()

elif num<1:

print("Kindly Enter The Positive Integer:")

else:

sum=0

while num>0:

sum+=num

num-=1

print("Sum Of Natural Number Are:%d"%sum)

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:

To write a program for perform find prime number using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

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:

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

19
PROGRAM CODE:
lower_value=int(input(" Please Enter the lowest limit:"))

high_value=int(input("please enter the highest limit:"))

print(" the prime number in the range are:")

for number in range(lower_value,high_value+1):

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:

To write a program for perform area calculation using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: create function for calculate the area of shapes.


def areaRectangle(length,breath):

def areaSquare(side)

def areaCircle(rad)

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

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\tAREA CALCULATION IN USERSS DEFINED METHOD")

print("\t\t***************************************************")

print('Enter The Following Values For Rectangle')

lengthRect=int(input('length:'))

breathRect=int(input('breath:'))

areaRect=areaRectangle(lengthRect,breathRect)

print('Area Of Rectangle Is:',areaRect)

sideSqr=int(input('Enter The Side Of Square :'))

areaSqr=areaSquare(sideSqr)

print('Area Of Square Is:',areaSqr)

radius1=float(input('Enter The Radius Value:'))

23
areacir=areaCircle(radius1)

print('Area Of Circle is:',areacir)

print('Enter The Following Values For Triangle')

side1=float(input("Enter Length Of First Side:"))

side2=float(input("Enter Length Of Second Side:"))

side3=float(input("Enter Length Of Third Side:"))

areaTri=areaTriangle(side1,side2,side3)

print('Area Of Triangle Is:',areaTri)

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:

To write a program for find a factorial number using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: create a function.

def recur_factorial(n):

if n==1:

return n

else:

return n*recur_factorial(n-1)

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

26
PROGRAM CODE:
def recur_factorial(n):

if n==1:

return n

else:

return n*recur_factorial(n-1)

num=7

if num<0:

print("sorry,factorial does not exist for negative number")

elif num==0:

print("the factorial of 0 is 1")

else:

print("the factorial of",num ,"is",recur_factorial(num))

27
OUTPUT:

RESULT:
Thus the given program has been executed successfully and output was verified

28
EX.NO: 5
EXCEPTION HANDLING
DATE:

AIM:

To write a program for find a factorial number using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: create a main function.


def main():

price=input('Enter The Price Of Item Purchased-->:')

weight=input('Enter The Weight Of Item Purchased-->:')

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

29
PROGRAM CODE:
import sys

def main():

price=input('Enter The Price Of Item Purchased-->:')

weight=input('Enter The Weight Of Item Purchased-->:')

try:

if price == ' ': price = None

price=float(price)

if weight == ' ' :weight = None

weight=float(weight)

assert price>=0 and weight>=0

result=price/weight

except ValueError:

print('Invalid inputs :VALUEERROR')

except TypeError:

print('Invalid inputs :TYPEERROR')

except ZeroDivisionError:

print('Invalid inputs :ZeroDivisionError')

except:

print(str(sys.exc_info()))

else:

print('Price Per Unit Weight-->:',result)

30
OUTPUT:

RESULT:
Thus the given program has been executed successfully and output was verified

31
EX.NO: 6(a)
MULTIPLE INHERITANCE
DATE:

AIM:

To write a program for multiple inheritance using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


class university:

def __init__(self):

print("constructor of the bass class")

self.univ="MKU"

def display(self):

print("the university name is:" self.univ)

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

32
PROGRAM CODE:
class university:

def __init__(self):

print("constructor of the bass class")

self.univ="MKU"

def display(self):

print("the university name is:" self.univ)

class course(university):

def __init__(self):

print("constructor of the child class 1 of class university")

university.__init__(self)

self.course="BSC"

def display(self):

print(f"the course name is:"self.course)

university.display(self)

class branch(university):

def __init__(self):

print("constructor of the child class 2 of class university")

self.branch="PYTHON"

def display(self):

print(f"the branch name is:"self.branch)

class student(course,branch):

def __init__(self):

print("constructor of child class of course and branch is called")

33
self.name="ABI"

branch.__init__(self)

course.__init__(self)

def display(self):

print(f"the name of the student is:"self.name)

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:

To write a program for multilevel inheritance using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


class a:

def getdata(self):

self.__name=input("enter name:")

self.__rollno=int(input("enter roll number:"))

self.__sal=int(input("enter salary:"))

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

36
PROGRAM CODE:
class Student:

def getStudentInfo(self):

self.__rollno=input("enter roll number:")

self.__name=input("enter name:")

def printStudentInfo(self):

print("roll number: " ,self.__rollno,"name: " , self.__name)

class Bsc(Student):

def getBsc(self):

self.getStudentInfo()

self.__p=int(input("enter physics marks:"))

self.__c=int(input("enter chem marks:"))

self.__m=int(input("enter maths marks:"))

def printBsc(self):

self.printStudentInfo()

print("marks in different subjects:",self.__p,self.__c,self.__m)

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()

print("total marks out of 300:",self.__total)

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:

To write a program for hierarical inheritance using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


class details:

def __init__(self):

self.__id="<no id>"

self.__name="<no name>"

self.__gender="<no gender>"

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

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()

print("|n doctor object")

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:

To write a program for hybrid inheritance using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


class details:

def __init__(self):

self.__id="<no id>"

self.__name="<no name>"

self.__gender="<no gender>"

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

43
PROGRAM CODE:
class university:

def __init__(self):

print("constructor of the base class")

self.univ="MKU,TKS COLLEGE"

def display(self):

print(f"the university name is:{self.univ}")

class course(university):

def __init__(self):

print("constructor of the child class 1 of class university")

university.__init__(self)

self.course="Bsc.COMPUTER SCIENCE"

def display(self):

print("the course name is:",self.course)

university.display(self)

class branch(university):

def __init__(self):

print("constructor of the child class 2 of class university")

self.branch="OOPS"

def display(self):

print("the branch name is:",self.branch)

class student(course,branch):

def __init__(self):

print("constructor of child class of course and branch is called")

44
self.name="MSP"

branch.__init__(self)

course.__init__(self)

def display(self):

print("the name of the student is:",self.name)

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:

To write a program for polymorphism using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


class Cat:

def __init__(self, name, age):

self.name = name

self.age = age

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

47
PROGRAM CODE:
class Cat:

def __init__(self, name, age):

self.name = name

self.age = age

def info(self):

print(f"I am a cat. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):

print("Meow")

class Dog:

def __init__(self, name, age):

self.name = name

self.age = age

def info(self):

print(f"I am a dog. My name is {self.name}. I am {self.age} years old.")

def make_sound(self):

print("Bark")

cat1 = Cat("Kitty", 2.5)

dog1 = Dog("Fluffy", 4)

for animal in (cat1, dog1):

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:

To write a program for files operations using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: declare a class


def writelines():

outfile=open('myfile.txt','w')

while True:

line=input('enter line:')

line +='\n'

outfile.write(line)

choice=input('are there more lines y/n?')

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

50
PROGRAM CODE:
def writelines():

outfile=open('myfile.txt','w')

while True:

line=input('enter line:')

line +='\n'

outfile.write(line)

choice=input('are there more lines y/n?')

if choice=='n':

break

outfile.close()

writelines()

def count_word():

file = open('myfile.txt','r')

count = 0

for line in file:

words = line.split()

for word in words:

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:

To write a program for module using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: Type the program

Step 4: code for my.py


def large(a,b):
if a<b:
return a
else:
return b

Step 5: Save the program.

Step 6: Display the output.

Step 7: Exit the program.

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:

To write a program for module using python.

ALGORITHM:

Step 1: Start the process

Step 2: Open the python IDLE

Step 3: First install the pip flask in python & configure the flask.

Step 4: Create a html form and save it a templates folder in a python

scripts path.

Step 5: create a app.py script to connect the html web page..

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.

Step 8: Display the output.

Step 9: Exit the program.

56
PROGRAM CODE:
App.py code:

from flask import Flask, request, render_template


app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
user_name = request.form['username']
return f'Hello, {user_name}!'
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)

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:

To run this program:

 Then copy the address: http://127.0.0.1:5000


 Paste a browser address bar

OUTPUT:

RESULT:
Thus the given program has been executed successfully and output was verified

58

You might also like