0% found this document useful (0 votes)
6 views23 pages

PP, 210303126039, Pandya Mayur

Uploaded by

Akshat Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views23 pages

PP, 210303126039, Pandya Mayur

Uploaded by

Akshat Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

FACULTY OF ENGINEERING &

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

PYTHON PROGRAMMING (203105211)


AY

3RD SEMESTER
M

COMPUTER SCIENCE ENGINEERING TECHNOLOGY


FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
2

CERTIFICATE

This is to certify that

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)

1 WAP to read and display the

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.

4 Write a Function to swap values

,6
of a pair of integers.
YA
5 WAP to find N! Using function.

6 WAP to print Fibonacci series of


D

‘n’ numbers, where n is given by


the programmer.
N

7 WAP to read a set of numbers in


PA

an array & to find the largest of


them.

8 WAP to sort a list of names in


R

ascending order.
U

9 WAP to read a set of numbers from


keyboard & to find the sum of all
AY

elements of the given array using


a function
M

10 Calculate area of different


geometrical figures (circle,
rectangle, square, and triangle).
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
4

11 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 member
function.

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

AIM:- Write a Function to swap values of a pair of integers.


R

APPARATUS:-python compiler online/offline,internet,computer/laptop.


U
AY

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

AIM:- WAP to find N! Using function.


APPARATUS:-python compiler online/offline,internet,computer/laptop.
AY

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

1:-#FIBONACCI SERIES BY USING FUNCTION


n=int(input("Enter the number"))
def fib(n):
a=0
b=1
if n == 1:
print(a)
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
11
else:
print(a)
print(b)
for i in range(2,n):
c=a+b
a=b
b=c

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

AIM:- WAP to sort a list of names in ascending order.


APPARATUS:-python compiler online/offline,internet,computer/laptop.
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
14

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

n=int(input("Enter the length:-"))


for i in range(0,n):
N

l=int(input("Enter the element:-"))


PA

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

AIM:- Calculate area of different geometrical figures (circle, rectangle, square,


and triangle)
APPARATUS:-python compiler online/offline,internet,computer/laptop.

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

b=int(input("Enter the value of b"))


print(areaoftriangle())
FACULTY OF ENGINEERING &
TECHNOLOGY,PP(203105211),B.TECH
ERP:-210303126039
18
OUTPUT:-

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

APPARATUS:-python compiler online/offline,internet,computer/laptop.


AY

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

print("Enter the Employee Name, id , designation and salary")

name = input("Enter the Employee Name: ")


id = input("Enter the Employee id: ")
designation = input("Enter the Employee designation: ")

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("Output of Read function is ")


N

print(file1.read())
PA

print()

file1.seek(0)
R

print( "Output of Readline function is ")


U

print(file1.readline())
AY

print()

file1.seek(0)
M

print("Output of Read(9) function is ")


print(file1.read(9))
print()

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy