pythonmanual
pythonmanual
PYTHON PROGRAMMING
LAB
(CODE: VSEC202)
Name:
Class: FE Computer Engineering & Civil & Planning
Semester:II
Roll No:
Batch:
BY
ENGINEERING
Date :-
COLLEGE SEAL
32
INDEX
Ex
p. Experiment Name Lab Date of Date of Marks Sign.
Performance Completion
No. Objective
1 Personalized Greeting Generator
Calculating Area of circle
LO1
Calculating Gross Salary of an
employee
Calculating Simple Interest
Exploring Basic Arithmetic Operations
in Python
Task List Manager LO1
2
Student Enrollment Manager LO1
3
Student Record Keeper LO1
4
33
14 GUI for Developing coversion utilities LO5
TOTAL MARKS
34
DEPARTMENT OF COMPUTER ENGINEERING
Lab Objectives:
1. To familiarize learners with Python's basic syntax, variables, data types, operators, and
input/output functions.
2. To reinforce the understanding and application of conditional statements, loops, and
functions in Python programming.
3. To instill learners on file handling, exception management, and Python packaging.
4. To Introduce object-oriented programming principles and their application in Python.
5. To explore advanced topics such as regular expressions, pattern matching, and GUI
development.
6. To introduce and demonstrate the use of popular Python libraries for data handling
Lab Outcome:-
1. Demonstrate the proficiency in basic python programming or Create and perform various
operations on data structures like list, tuple dictionaries and strings.
2. Apply Control Flow and Functions for efficient coding to solve problems.
3. Demonstrate proficiency in handling file operations, managing exceptions, and
developing Python packages and executable files for modular programming.
4. Illustrate the concept of Object-Oriented Programming used in python.
5. Design Graphical User Interface (GUI) applications, utilizing appropriate Python
libraries to create user-friendly interfaces.
6. Investigate and apply popular python libraries to conduct efficient data handling tasks..
Term Work:
35
EXPERIMENT NO:-1
Program 1.1
Aim:- Write A Python Program To Generate Personalized Greetings
Code:
print("Personalised Greeting")
DAY=input("HOW WAS YOUR DAY:")
print("YOUR DAY WAS :",DAY)
Output:-
Program 1.2
Code:-
length=int(input("ENTER THE LENGTH:"))
breadth=int(input("ENTER THE BREADTH:"))
area=length*breadth
print("AREA OF RECTANGLE IS :",area)
Output:-
Program 1.3
Code:-
base=int(input("ENTER THE BASE:"))
height=int(input("ENTER THE HEIGHT:"))
area=0.5*base*height
print("THE AREA OF TRIANGLE IS :",area)
36
Output:-
Program 1.4
Code:-
r=int(input("enter the radius of circle:"))
a=3.14*r*r
print("The Area of Circle is :",a)
Output:-
Program 1.5
Code:-
rupees=float(input("enter rupees:"))
dollar=rupees/81.86
print("The Dollar is:",dollar)
Output:-
Program 1.6
Code:-
37
Output:-
Program 1.7
Code:-
inches=float(input("ENTER THE MEASURE IN INCHES:"))
feet=inches/12
print("THE MEASURE IN FEET IS:",feet)
Output:-
Program 1.8
Code:-
P=int(input("Enter the principle ammount:"))
N=int(input("Enter the year:"))
R=float(input("Enter the rate of principle interest:"))
si=(P*N*R/100)
print("Simple interest = ",si)
Output:-
38
Program 1.9
Code:-
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
print("Addition is:",a+b)
print("Subtraction is:",a-b)
print("Multiplication is:",a*b)
print("Division is :",float(a/b))
Output:-
Program 1.10
Aim:-Write a program to calculate gross salary of an employee take theBasic salary (BS) as
an input from the user and calculate DA=70% of BS, HRA=10% of BS, and TA=30% of
BS and calculate gross salary.
Code:-
basicsalary=float(input("ENTER THE BASIC SALARY:"))
da=0.7*basicsalary
hra=0.1*basicsalary
ta=0.3*basicsalary
grosssalary=basicsalary+da+ta+hra
print("THE GROSS SALARY IS :",grosssalary)
Output:
39
EXPERIMENT NO:-2
Aim:- Develop a Python program to manage a task list using lists and tuples, including
adding, removing, updating, and sorting tasks.
Code:-
l=[10,20,30,40,50] #To create a list
print(l)
print(l[0]) #To access the element in the list
l=[15,25,35,45,55]
print(l[1:4]) #To access certain elements in the list
l=[12,26,39,41,53]
l[0]=80 #To access specific element in the list
print(l)
l=[14,23,38,47,50]
l[1]=[5,85] #To add elements in the list
print(l)
l=[13,60,31,44,53]
l.append(50) #To append element in the list
print(l)
l=[21,43,55,67,78]
l.extend([70,80]) #To extend elements in the list
print(l)
l=[30,20,10,5,2]
l.sort() #To sort elements in the list
print(l)
l=[40,20,10,5,2]
l.reverse() #To reverse the elements in the list
print(l)
l=[18,66,44,24,12]
l.pop() #To POP element from the list
print(l)
l.remove(66) #To remove element from the list
print(l)
del l[0] #To delete element from the list
print(l)
Output:-
31
0
Program 2.2
Output:-
Conclusion:-Thus we have developed a Python program to manage a task list using lists and
tuples, including adding, removing, updating, and sorting tasks
31
1
EXPERIMENT NO:-3
Program 3.1
Aim:- Create a Python code to demonstrate the use of sets and perform set operations
(union, intersection, difference) to manage student enrollments in multiple courses /
appearing for multiple entrance exams like CET, JEE, NEET etc.
Code:-
#Create set to manage student enrollment in multiple courses for multiple exams
all_students=set.union(JEEE|CET|NEET)
print("Total students registered for entrance exam this year:\n", all_students)
common= (JEEE&CET&NEET)
print("Student enrolled in all three exams:\n", common)
unique=(JEEE-CET-NEET)
print("Student enrolled in only one exam:\n", unique)
unique=(JEEE^CET^NEET)
print("Student enrolled in all or only one exam:\n", unique)
Output:-
Conclusion:-Thus we have developed python code to demonstrate the use of sets and
perform set operations (union, intersection, difference).
31
2
EXPERIMENT NO:-4
Program 4.1
Aim:- Write a Python program to create, update, and manipulate a dictionary of student
records, including their grades and attendance.
Code:-
Output:-
31
3
EXPERIMENT NO:-5
Program 5.1
Aim:-Develop a Python program that takes a numerical input and identifies whether it is
even or odd, utilizing conditional statements and loops
Code:-
Output:-
Conclusion:-Thus we have implemented Python program that takes a numerical input and
identifies whether it is even or odd, utilizing conditional statements and loops.
31
4
EXPERIMENT NO:-6
Factorial Generator
Program 6.1
Code:-
f=1
i=1
n=int(input("Enter the number:"))
while i<=n:
f=f*i
i=i+1
print(f)
Output:-
Program 6.2
Aim:- Write a program to calculate factorial of any number using for loop.
Code:-
f=1
n=int(input("Enter a number:"))
for i in range (1,n+1):
f=f*i
print(f)
Output:-
31
5
EXPERIMENT NO:-7
Program 7.1
Aim:-Using function, write a Python program to analyze the input number is prime or not
Code:-
Output:-
31
6
EXPERIMENT NO:-8
Program 8.1
Aim:-Implement a simple Python calculator that takes user input and performs basic
arithmetic operations (addition, subtraction, multiplication, division) using functions.
Code:-
x=int(input("Enter 1st number")
y=int(input("Enter 2nd number"))
def add():
z=x+y
print(z)
add()
def sub():
z=x-y
print(z)
sub()
def mul():
z=x*y
print(z)
mul()
def div():
z=x/y
print(z)
div()
Output:-
31
7
EXPERIMENT NO:-9
Program 9.1
Aim:- Develop a Python program that reads a text file and prints words of specified lengths
(e.g., three, four, five, etc.) found within the file
Code:-
f="word.txt"
l=w=c=0
with open (“f ",r") as file:
for line in file:
l=l+1
w=w+len(line.split())
c=c+len(line)
print(l)
print(w)
print(c)
Output:-
Conclusion:- Thus we have implemented python programs for that reads a text file and
prints words of specified lengths.
31
8
EXPERIMENT NO:-10
Building an Executable File
Aim:- Create a executable file for any program developed in earlier practical
Steps:-
Step 1:- Open Command Prompt and write cd/
Step 6:- Save the python program file word.py in the path -
C:\Users\Lab1020\AppData\Local\Programs\Python\Python313\Scripts
Step 7:- Run the command pyinstaller -F word.py
Step8:- The executable file has been created now, to check:
Open the Folder “dist”
Output:-
Conclusion:- Thus we have created a executable file for any program developed in
earlier practical
31
9
EXPERIMENT NO:-11
Program 11.1
Aim:- Write a Python program that takes two numbers as input and performs division.
Implement exception handling to manage division by zero and invalid input errors
gracefully.
Code:-
try:
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
result = num1 / num
print(result)
except ValueError as e:
print("Invalid Input Please Input Integer...")
except ZeroDivisionError as e:
print(e)
Output:
32
0
32
1