PP, 210303126039, Pandya Mayur
PP, 210303126039, Pandya Mayur
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
1
ET
PYTHON PROGRAMMING
PI
LAB MANUAL
9,
03
,6
YA
FACULTY OF ENGINEERING AND
TECHNOLOGY
D
N
PA
BACHELOR OF TECHNOLOGY
R
U
3RD SEMESTER
M
CERTIFICATE
ET
Mr./Ms Mayurkumar Sanjaybhai Pandya, Enrolment No
PI
201303126039, has successfully Completed his/her laboratory
9,
experiments in the PYTHON PROGRAMMING (203105211) from the
03
department of CSE-CS
,6
During the academic year 2022-23
YA
D
N
PA
R
U
AY
M
Date of Submission:.........................
Staff In charge:...........................
Head of Department:...........................................
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
3
TABLE OF CONTENTS
Sr. Experiment Title Page No Date of Date of Sign Mar
No Performance Assessment ks
From To (out
of
10)
ET
following information. Name,
Address, Phone no.
PI
2 WAP to read two numbers from
the keyboard and display the
larger one on the screen.
9,
3 WAP to find, a given number is
03
PRIME or NOT.
,6
of a pair of integers.
YA
5 WAP to find N! Using function.
ascending order.
U
ET
12 WAP to read data from keyboard &
write it to the file. After writing is
PI
completed, the file is closed. The
program again opens the same file
9,
and reads it.
03
,6
YA
D
N
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
5
PRACTICAL 1
ET
AIM:- WAP to read and display the following information. Name, Address, Phone
no.
PI
APPARATUS:-python compiler online/offline,internet,computer/laptop.
9,
INPUT:-
03
N="Mayur"
,6
A="anand"
MN=9727993640
YA
print("Name="+N)
print("Address="+A)
print("Mobileno="+str(MN))
D
N
OUTPUT:-
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
6
PRACTICAL 2
ET
AIM:- WAP to read two numbers from the keyboard and display the larger one on
the screen.
APPARATUS:-python compiler online/offline,internet,computer/laptop.
PI
9,
INPUT:-
num1=int(input("enter your no.="))
03
num2=int(input("enter your no.="))
if num1>num2:
,6
print("num1 is greater than num2")
else:
YA
print("num2 is greater than num 1")
OUTPUT:-
D
N
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
7
PRACTICAL 3
ET
AIM:- WAP to find, a given number is PRIME or NOT.
PI
APPARATUS:-python compiler online/offline,internet,computer/laptop.
9,
INPUT:-
03
x=int(input("Enter any number:-"))
if(x>1):
,6
for i in range(2,x):
if(x%i) == 0:
YA
print("NUmber is not prime")
break
else:
D
print("NUmber is prime")
N
OUTPUT:-
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
8
ET
PI
9,
03
,6
YA
D
PRACTICAL 4
N
PA
INPUT:-
x=input("Enter any number=")
y=input("Enter any number=")
M
x,y=y,x
print("swap number are = "+x+"and"+y)
OUTPUT:-
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
9
ET
PI
9,
03
,6
YA
D
N
PA
PRACTICAL 5
R
U
INPUT:-
n=int(input('ENTER A NUMBER:-'))
M
def factorial(n):
if n==0 or n==1:
print('factorial is 1')
elif n>1:
fact=1
for i in range(1,n+1):
fact=fact*i
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
10
print('factorial is',fact)
print(factorial(n))
OUTPUT:-
ET
PI
9,
03
,6
YA
D
N
PA
PRACTICAL 6
R
AIM:- WAP to print Fibonacci series of ‘n’ numbers, where n is given by the
U
programmer.
APPARATUS:-python compiler online/offline,internet,computer/laptop.
AY
INPUT:-
M
ET
print(c)
print(fib(n))
PI
2:- #FIBONACCI SERIES WITHOUT USING FUNCTION
n=int(input("ENTER THE LIMIT"))
9,
a=0
03
b=1
print(a)
,6
print(b)
for i in range(0,n-2):
YA
c=a+b
a=b
b=c
D
print(c)
N
PA
R
U
OUTPUT:-
AY
1:-WITH FUNCTION
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
12
ET
PI
9,
03
2:-WITHOUT FUNCTION
,6
YA
D
N
PA
R
U
AY
M
PRACTICAL 7
AIM:- WAP to read a set of numbers in an array & to find the largest of them.
APPARATUS:-python compiler online/offline,internet,computer/laptop.
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
13
INPUT:-
list=[]
n=int(input("Enter the length "))
for i in range(0,n):
l=int(input("Enter the element"))
list.append(l)
ET
print(list)
print("max element",max(list) )
PI
9,
OUTPUT:-
03
,6
YA
D
N
PA
R
U
AY
M
PRACTICAL 8
INPUT:-
namelist=[]
n=int(input("Enter the length:-"))
for i in range(0,n):
l=input("Enter the name:-")
namelist.append(l)
ET
namelist.sort()
PI
print("acending order:- ",namelist)
9,
OUTPUT:-
03
,6
YA
D
N
PA
R
U
AY
M
PRACTICAL 9
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
15
AIM:- WAP to read a set of numbers from keyboard & to find the sum of all
elements of the given array using a function
APPARATUS:-python compiler online/offline,internet,computer/laptop.
INPUT:-
1:- BY USING ARRAY
ET
import array as ar
def Sum(arr):
PI
sum=0
n = len(arr)
9,
for i in range(n):
sum = sum + arr[i]
03
return sum
a = ar.array('i',[10, 21, 12, 13])
,6
print ('Sum of the array is ', Sum(a) )
YA
2:-BY USING LIST
list=[]
D
list.append(l)
print(list)
print("Sum of list:- ",sum(list))
R
U
AY
M
OUTPUT:-
1:- BY USING ARRAY
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
16
ET
PI
9,
03
,6
YA
2:- BY USING LIST
D
N
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
17
PRACTICAL 10
ET
INPUT:-
#area of circle
PI
def areaofcircle():
areaofcircle=3.14*(r*r)
9,
print("area of circle is=",areaofcircle)
r=int(input("enter radius:"))
03
print(areaofcircle())
#area of rectangle
,6
def areaofrectangle():
areaofrectangle =l*b
YA
print("area of rectangle=",areaofrectangle)
l=int(input("Enter the value of l"))
b=int(input("Enter the value of b"))
D
print(areaofrectangle())
N
#area of square
def areaofsquare():
PA
areaofsquare=s**2
print("area of square=",areaofsquare)
s=int(input("Enter the side of square"))
R
print(areaofsquare())
U
#area of triangle
def areaoftriangle():
AY
areaoftriangle=1/2*l*b
print("area of triangle=",areaoftriangle)
l=int(input("Enter the value of l"))
M
ET
PI
9,
03
,6
YA
D
PRACTICAL 11
N
PA
AIM:- WAP to increment the employee salaries on the basis of their designation
(Manager-5000, General Manager-10000, CEO-20000, worker-2000). Use
employee name, id, designation and salary as data member and inc_sal as
R
member function.
U
INPUT:-
def inc_sal(salary, designation):
M
if designation == 'Manager':
salary = salary + 5000
elif designation == 'General Manager':
salary = salary + 10000
elif designation == 'CEO':
salary = salary + 20000
else:
salary = salary + 2000
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
19
return salary
ET
salary = int(input("Enter the Employee salary: "))
salary = inc_sal(salary, designation)
print("The Employee Name is: ", name)
PI
print("The Employee id is: ", id)
print("The Employee designation is: ", designation)
9,
print("The Employee salary is: ", salary)
03
,6
OUTPUT:-
YA
D
N
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
20
PRACTICAL 12
AIM:- WAP to read data from keyboard & write it to the file. After writing is
completed, the file is closed. The program again opens the same file and
ET
reads it.
APPARATUS:-python compiler online/offline,internet,computer/laptop.
PI
INPUT:-
9,
file1 = open("myfile.txt","w")
03
L = ["This is Delhi \n","This is Paris \n","This is London \n"]
file1.write("Hello \n")
file1.writelines(L)
,6
YA
file1.close()
file1 = open("myfile.txt","r+")
D
print(file1.read())
PA
print()
file1.seek(0)
R
print(file1.readline())
AY
print()
file1.seek(0)
M
file1.seek(0)
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
21
print("Output of Readline(9) function is ")
print(file1.readline(9))
file1.seek(0)
# readlines function
print("Output of Readlines function is ")
print(file1.readlines())
ET
print()
file1.close()
PI
0r
9,
03
text_file=open("readme.text","w")
text_file.write("hello\n")
,6
text_file.write("i'm learning python\n")
text_file.write("bye!")
YA
text_file.close()
file=open("readme.txt","r")
for line in file:
D
print(line)
N
PA
OUTPUT:-
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
22
ET
PI
9,
03
,6
YA
D
N
PA
R
U
AY
M
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
23
ET
PI
9,
03
,6
YA
D
N
PA
R
U
AY
M