Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

FACULTY OF ENGINERING &TECHNOLOG

Subject name:- python programing


Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

PRACTICAL-01

AIM:-Write a program to read and display the following


information,Name,Address,Phone no.

PROGRAM:- name = input("Enter your name:")


address = input("Enter your address:")
number = input("Enter your telephone number:")
print("Your details are:", name, address, number,
sep="\n")

OUTPUT:-

PRACTICAL-02
AIM:- WAP to read two numbers from the keyboard and display the
larger one on the screen

PROGRAM:- num1 = int(input("Enter first number :"))


num2 = int(input("Enter second number :"))
if (num1 > num2):

ENROLLMENT NO :-210303105344 1
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

print(num1,"is larger than",num2)


elif (num1 == num2):
print(num1,"is equal to",num2)
else :
print(num1,"is smaller than",num2)

OUTPUT:-

PRACTICAL-03
AIM:- WAP to find, a given number is PRIME or NOT.

PROGRAM:- number = int(input("Enter any number: ")) if

number > 1:

for i in range(2, number):


if (number % i) == 0:
print(number, "is not a prime number")
break else: print(number, "is a prime
number") else:

ENROLLMENT NO :-210303105344 2
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

print(number, "is not a prime number")


OUTPUT:-

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

PROGRAM:-
P = int( input("Please enter value for P: ")) Q =

int( input("Please enter value for Q: ")) temp_1 =

P P=Q

Q = temp_1

print ("The Value of P after swapping: ", P) print

("The Value of Q after swapping: ", Q)

ENROLLMENT NO :-210303105344 3
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

OUTPUT:-

PRACTICAL-05
AIM:- WAP to find N! Using function.

PROGRAM:-
num = int(input("Enter a number: "))

factorial = 1 if num < 0:

print("Sorry, factorial does not exist for negative


numbers") elif num == 0:

print("The factorial of 0 is 1") else: for i in

range(1,num + 1): factorial = factorial*i

print("The factorial of",num,"is",factorial)

OUTPUT:-

ENROLLMENT NO :-210303105344 4
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

PRACTICAL-06
AIM:- WAP to print Fibonacci series of ‘n’ numbers, where n is given by the
programmer.

PROGRAM:- nterms = int(input("How many terms? "))


n1, n2 = 0, 1

count = 0 if

nterms <= 0:

print("Please enter a positive integer") elif

nterms == 1:

print("Fibonacci sequence upto",nterms,":")

print(n1) else:

print("Fibonacci sequence:") while

count < nterms:

print(n1) nth = n1 + n2 n1 = n2 n2 = nth count

+= 1

OUTPUT:-

PRACTICAL-07
AIM:- WAP to read a set of numbers in an array & to
find the largest of them

PROGRAM:- def largest(arr,n):

ENROLLMENT NO :-210303105344 5
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

mx = arr[0] for i

in range(1, n): if arr[i]

> mx:

mx = arr[i]

return mx arr = [10, 324, 45, 90, 9808] n =

len(arr) Ans = largest(arr,n) print ("Largest

in given array is",Ans)

OUTPUT:-2qv6by666662qtyvb6tvb5q2

PRACTICAL-08
AIM:- WAP to sort a list of names in ascending order.
PROGRAM:- lst = ['gfg', 'is', 'a', 'portal', 'for', 'geeks'] lst.sort()

print(lst)

ENROLLMENT NO :-210303105344 6
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

OUTPUT:-

ENROLLMENT NO :-210303105344 7
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

PRACTICAL-09

AIM:- WAP to read a set of numbers from keyboard & to find the sum of all
elements of the given array using a function

PROGRAM:- def _sum(arr):


sum = 0
for i in arr:
sum = sum + i

return(sum) arr =
[] arr = [12, 3, 4, 15]
n = len(arr)

ans = _sum(arr) print('Sum of the


array is ', ans)

OUTPUT:-

ENROLLMENT NO :-210303105344 8
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

PRACTICAL-10
AIM:- Calculate area of different geometrical figures (circle, rectangle, square,
and triangle).

PROGRAM:- def calculate_area(name):


name = name.lower() if
name == "rectangle":
l = int(input("Enter rectangle's length: ")) b =
int(input("Enter rectangle's breadth: ")) rect_area
= l * b print(f"The area of rectangle is
{rect_area}.")

elif name == "square":


s = int(input("Enter square's side length: ")) sqt_area
=s*s
print(f"The area of square is
{sqt_area}.")

elif name == "triangle":


h = int(input("Enter triangle's height length: ")) b =
int(input("Enter triangle's breadth length: ")) tri_area =
0.5 * b * h print(f"The area of triangle is
{tri_area}.")

elif name == "circle":


r = int(input("Enter circle's radius length: ")) pi =
3.14 circ_area = pi * r * r print(f"The area of circle
is
{circ_area}.")

else:
print("Sorry! This shape is not available")

ENROLLMENT NO :-210303105344
9
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

OUTPUT:-

ENROLLMENT NO :-210303105344
10
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

PRACTICAL-11

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

PROGRAM:- class
Employee:

def
__init__(self,emp_name,desig nation,salary):

self.emp_namee

mp_name

self.designation

designation

self.salary = salary

def inc_sal(self):

self.designation=s

elf.lower() if

ENROLLMENT NO :-210303105344
11
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

self.designation== 'manager':

self.salary += 5000

if

self.designation=='g eneral

manager':

self.salary +=

10000 if self.designation=='

ceo':

self.salary += 20000

if self.designati

on=='worker':

self.salary += 2000

def display(self): print("Employee

Name: ",self.emp_name)

print("Employee Designation:

",self.designation)

ENROLLMENT NO :-210303105344
12
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

print("Employee Increased Salary:


",self.salary)

emp =
Employee('Prakash','ceo',800
00) emp.inc_sal() emp.display()

emp2 =

Employee('Abhay','General

Manager',40000) emp2.inc_sal()

emp2.display()

OUTPUT:-

ENROLLMENT NO :-210303105344
13
FACULTY OF ENGINERING &TECHNOLOG
Subject name:- python programing
Subject code:-203105212
B. Tech. 2 YEAR 3 Semester

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 reads
it.

PROGRAM:-
F=open(“file.txt”,”w”)
F.write(“/n hello everyone /n how are u”)
F.write(“hope u all are alright”)
F.close()

with open(“file”) as F:
A=F.readline()
B=F.readlines()

Print(A) Print(B)

Output:

ENROLLMENT NO :-210303105344
14

You might also like