0% found this document useful (0 votes)
2 views20 pages

Final Python Record

The document outlines the Python Programming Lab course for B.Tech II Semester students at the Hyderabad Institute of Technology and Management. It includes a detailed index of programming exercises and their outputs, covering topics such as data types, control structures, functions, classes, and threading. The lab work is supervised by faculty members and includes a certification of completion for the student, KATARAM VISHNUVARDHAN.

Uploaded by

n5504130ab
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)
2 views20 pages

Final Python Record

The document outlines the Python Programming Lab course for B.Tech II Semester students at the Hyderabad Institute of Technology and Management. It includes a detailed index of programming exercises and their outputs, covering topics such as data types, control structures, functions, classes, and threading. The lab work is supervised by faculty members and includes a certification of completion for the student, KATARAM VISHNUVARDHAN.

Uploaded by

n5504130ab
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

PYTHON PROGRAMMING LAB

(R-HR24-I [Link] II Semester)

Course Code:24ES2CS02

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


(AI & ML)

Prepared By

KATARAM VISHNUVARDHAN
25E51A6683

HYDERABAD INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Gowdavalli(V), Medchal Mandal , Hyderabad-501401

(Accredited by NAAC A+, NBA, Affiliated to JNTU, Hyderabad, TS)

2025-2026
HYDERABAD INSTITUTE OF TECHNOLOGY AND MANAGEMENT
UG AUTONOMOUS COLLEGE CERTIFICATE

PYTHON PROGRAMMING LAB

LABORATORY: Python Programming lab ACADEMIC YEAR: 2025-2026

Certified that is the Bonafide record of work done by Mr/Mrs KATARAM VISHNUVARDHAN

Of I Year [Link] – II Semester, Branch CSM (AI & ML)

With Hall Ticket No 25E51A6683 And performed 24

No. of Programs under my Supervision.

Faculty In Charge Dean Freshman


Dr. G. Aparna Dr. S.V. Chandra Mouli
Associate Professor Professor

External Examiner Head of the Department


Dr. T. Rambabu
Professor & HOD
INDEX
WEEKS Sl.
NO NAME OF THE PROGRAM PAGE MARKS SIGNATURE REMARKS
NO.
Read the temperature in centigrade and convert 4
1 it into Fahrenheit.
Consider two Numbers as input and swap those 4
WEEK 1
2 two values without using 3rd variable.
Read a list of numbers and write a program to 4
3 check whether a particular element is present or
not using membership opertors.
Read name, address, email, and phone number of 5
4 a person through keyboard and print the details.
WEEK 2 Read the year and check whether that year is a 5
5 leap year or not.
Read 4 numbers and find maximum & minimum 6
6 among those number.
Write a program to check whether the given 7
7 input is digit or lowercase character or uppercase
WEEK 3 character or a special character. (use ‘if-else-if’
ladder)
Write a Python program to print even numbers 7
8 from 2000 to 2100 in a given interval (use break).
Given a list of tuples. Write a program to find 8
9 tuples which have all elements divisible by K from
a list of tuples. Test_list = [(6, 24, 12), (60, 12, 6),
WEEK 4 (12, 18, 21)], K = 6, Output : [(6, 24, 12), (60, 12,
6)].
Write a program to perform union, intersection 8
10 and difference using Set A and Set B.
Write a function called is_sorted that takes a list 9
11 as a parameter and returns True if the list is
sorted in ascending order and False otherwise
WEEK 5 Write a function called has_duplicates that takes 9
12 a list and returns True if there is any element that
appears more than once. It should not modify the
original list.
Write a recursive function to compute gcd, 10
WEEK 6 13 factorial, Fibonacci series.
14 Write a function to compute gcd, factorial, 11
Fibonacci series.
WEEKS Sl. PAGE MARKS SIGNATURE REMARKS
N NAME OF THE PROGRAM NO.
O
Write a program to create an employee class and 12
WEEK 7 15 store the employee name, id, age, and salary
using the constructor. Display the employee
details by invoking employee_info () method and
also using dictionary(__dict__).
16 Write a python program that defines a matrix and 13
prints
WEEK 8 17 Write a python program to perform addition of 13
two square matrices
18 Write a python program to perform 14
multiplication of two square matrices
19 Write a Python Program to find the roots of a 15
WEEK 9 quadratic equation and handle the appropriate
exception.
20 Write a python program to check a given phone 15
number is valid or not.
21 Write a Python program to create two threads 16-17
WEEK where thread1 will print the value from 1-20 and
10 thread2 prints from 21-40.
22 Write a Python program to multiply two n*n 17-18
matrices using n threads.
23 Write a Python program to copy the content of 19
WEEK given file to another a file.
11 24 Write a Python program to compute the number 19
of characters, words and lines in a file.
WEEK 1:

[Link] the temperature in centigrade and convert it into Fahrenheit.

c=25
f=(9*c/5)+32
print("Value of f:",f)

OUTPUT:

[Link] two Numbers as input and swap those two values without using 3rd variable

a=10
b=20
a,b = b,a
print(a,b)

OUTPUT:

[Link] a list of numbers and write a program to check whether a particular element is present or not using
membership opertors.

Numbers=["1","2","3","4","5","6","7"]
print('6' in Numbers)
print('8' not in Numbers)
print('8' in Numbers)

OUTPUT:

4
WEEK 2:

[Link] name, address, email, and phone number of a person through keyboard and print the details.

a=input("Enter Name:")
b=input("Enter Address:")
c=input("Enter E-Mail:")
d=int(input("Enter Phone Number:"))
print("------Details------")
print(a)
print(b)
print(c)
print(d)

OUTPUT:

Enter Name: Ramesh


Enter Address: Kukatpally, Hyderabad
Enter E-Mail: ramesh019@[Link]
Enter Phone Number: 9019019011
------Details------
Ramesh
Kukatpally, Hyderabad
ramesh019@[Link]
9019019011

[Link] the year and check whether that year is a leap year or not.

x = int(input("Enter any Year: "))


print(["Not a Leap Year", "Leap Year"][(x % 4 == 0)])

OUTPUT:

5
[Link] 4 numbers and find maximum & minimum among those number.

num1 = int(input("Enter number 1: "))


num2 = int(input("Enter number 2: "))
num3 = int(input("Enter number 3: "))
num4 = int(input("Enter number 4: "))
numbers = [num1, num2, num3, num4]
maximum = max(numbers)
minimum = min(numbers)
print("The maximum number is:", maximum)
print("The minimum number is:", minimum)

OUTPUT:

6
WEEK 3:

[Link] a program to check whether the given input is digit or lowercase character or uppercase character
or a special character (use ‘if-else-if’ ladder)

char = input("Press any Key: ")


if [Link]():
print("The Input key is Digit")
elif [Link]():
print("The Input key is Lowercase")
elif [Link]():
print("The Input key is Uppercase")
else:
print("The Input key is Special Character")

[Link] a Python program to print even numbers from 2000 to 2100 in a given interval (use break).

for num in range(2000,2101):


if num%2==0:
print(num)
if num==2100:
break

Output:
2000,2002,2004,………….,2100
7
WEEK 4:

9. Given a list of tuples. Write a program to find tuples which have all elements divisible by K from a list of
tuples. test_list = [(6, 24, 12), (60, 12, 6), (12, 18, 21)], K = 6, Output : [(6, 24, 12), (60, 12, 6)].

test_list = [(6,24,12),(12,60,6),(12,18,21)]
K=6
for tup in test_list:
flag = 1
for num in tup:
if num % K != 0:
flag = 0
if flag == 1:
print("The tuple with all elements divisible by K:", tup)

10. Write a program to perform union, intersection and difference using Set A and Set B.

set_A={1,2,3,4,5}
set_B={4,5,6,7,8}
print("Union:",set_A|set_B)
print("Intersection:",set_A&set_B)
print("Difference(A-B):",set_A-set_B)
print("Difference(B-A):",set_B-set_A)

OUTPUT:

8
WEEK 5:

11. Write a function called is_sorted that takes a list as a parameter and returns True if the list is sorted in
ascending order and False otherwise.

def is_sorted(lst):
return all(lst[i] <= lst[i+1] for i in range(len(lst)-1))
print(is_sorted([1,2,3,4]))
print(is_sorted([1,3,2,4]))

OUTPUT:

12. Write a function called has_duplicates that takes a list and returns True if there is any element that
appears more than once. It should not modify the original list.

def has_duplicates(lst):
return len(lst)!=len(set(lst))
print(has_duplicates([1,2,3,4]))
print(has_duplicates([1,2,3,2]))

OUTPUT:

9
WEEK 6:

13. Write a recursive function to compute gcd, factorial, fibonacci series.

def gcd(a, b):


if b == 0:
return a
else:
return gcd(b, a % b)
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
def fibonacci(n):
if n <= 0:
return "Invalid input"
elif n == 1:
return 0
elif n == 2:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
print("GCD of 48 and 18:", gcd(48, 18))
print("Factorial of 5:", factorial(5))
print("Fibonacci(10):", fibonacci(10))

OUTPUT:

10
14. Write a function to compute gcd, factorial, fibonacci series.
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
def fibonacci_series(n):
series = []
a, b = 0, 1
for _ in range(n):
[Link](a)
a, b = b, a + b
return series
print("GCD of 48 and 18:", gcd(48, 18))
print("Factorial of 5:", factorial(5))
print("Fibonacci series (10 terms):", fibonacci_series(10))

OUTPUT:

11
WEEK 7:

15. Write a program to create an employee class and store the employee name, id, age, and salary using the
constructor. Display the employee details by invoking employee_info () method and also using
dictionary(__dict__).

class Employee:
def __init__(self, name, emp_id, age, salary):
[Link] = name
self.emp_id = emp_id
[Link] = age
[Link] = salary
def employee_info(self):
print("Employee Information:")
print(f"Name : {[Link]}")
print(f"ID : {self.emp_id}")
print(f"Age : {[Link]}")
print(f"Salary : {[Link]}")
emp1 = Employee("Suresh", 101, 30, 55000)
emp1.employee_info()
print("\nEmployee details using __dict__:")
print(emp1.__dict__)

OUTPUT:

12
WEEK 8:
16. Write a python program that defines a matrix and prints

matrix=[[1,2,3],[4,5,6],[7,8,9]]
for row in matrix:
print(row)

OUTPUT:

17. Write a python program to perform addition of two square matrices

matrix1=[[1,2,3],[4,5,6],[7,8,9]]
matrix2=[[9,8,7],[6,5,4],[3,2,1]]
result=[[matrix1[i][j]+matrix2[i][j] for j in range(3)] for i in range(3)]
for row in result:
print(row)

OUTPUT:

13
18. Write a python program to perform multiplication of two square matrices

matrix1 = [[1,2,3],[4,5,6],[7,8,9]]
matrix2 = [[9,8,7],[6,5,4],[3,2,1]]
result = [[0]*3 for i in range(3)]
for i in range(3):
for j in range(3):
for k in range(3):
result[i][j] += matrix1[i][k] * matrix2[k][j]
for row in result:
print(row)

OUTPUT:

14
WEEK 9:

19. Write a Python Program to find the roots of a quadratic equation and handle the appropriate
exception.

import math
def find_roots(a, b, c):
try:
if a == 0:
raise ValueError("a cannot be 0")
d = b**2 - 4*a*c
if d < 0:
raise ValueError("Complex Roots")
r1 = (-b + [Link](d)) / (2*a)
r2 = (-b - [Link](d)) / (2*a)
print("Roots:", r1, r2)
except Exception as e:
print("Error:", e)
find_roots(1,8,15)

OUTPUT:

20. Write a python program to check a given phone number is valid or not.

def is_valid_phone(number):
return [Link]() and len(number)==10 and not [Link]('0')
print(is_valid_phone("9876543210"))
print(is_valid_phone("0123456789"))

OUTPUT:

WEEK 10:
15
[Link] a Python program to create two threads where thread1 will print the value from 1-20 and
thread2 prints from 21-40.

import threading
def print_numbers_1_to_20():
for i in range(1, 21):
print(f"Thread1: {i}")
def print_numbers_21_to_40():
for i in range(21, 41):
print(f"Thread2: {i}")
thread1 = [Link](target=print_numbers_1_to_20)
thread2 = [Link](target=print_numbers_21_to_40)
[Link]()
[Link]()
[Link]()
[Link]()

OUTPUT:
Thread1: 1
Thread1: 2
Thread1: 3
Thread1: 4
Thread1: 5
Thread1: 6
Thread1: 7
Thread1: 8
Thread1: 9
Thread1: 10
Thread1: 11
Thread1: 12
Thread1: 13
Thread1: 14
Thread1: 15
Thread2: 21
Thread2: 22
Thread2: 23
Thread2: 24
Thread2: 25
Thread2: 26
Thread2: 27
Thread2: 28
Thread2: 29
Thread2: 30
Thread2: 31
Thread2: 32

16
Thread2: 33
Thread2: 34
Thread2: 35
Thread2: 36
Thread2: 37
Thread2: 38
Thread2: 39
Thread2: 40
Thread1: 16
Thread1: 17
Thread1: 18
Thread1: 19
Thread1: 20

22. Write a Python program to multiply two n*n matrices using n threads

import threading
def multiply_row(A, B, result, row):
n = len(A)
for j in range(n):
result[row][j] = sum(A[row][k] * B[k][j] for k in range(n))
def matrix_multiply(A, B):
n = len(A)
result = [[0] * n for _ in range(n)]
threads = []
for i in range(n):
t = [Link](target=multiply_row, args=(A, B, result, i))
[Link](t)
[Link]()
for t in threads:
[Link]()
return result
if __name__ == "__main__":
A=[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
B=[
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
]
result = matrix_multiply(A, B)
print("Resultant Matrix:")
for row in result:
print(row)

17
OUTPUT:

18
WEEK 11:

23. Write a Python program to copy the content of given file to another a file.
source_file = open("[Link]", "r")
content = source_file.read()
destination_file = open("[Link]", "w")
destination_file.write(content)
source_file.close()
destination_file.close()
print("File copied successfully!")

OUTPUT:

24. Write a Python program to compute the number of characters, words and lines in a file.

file=open("[Link]","r")
chars=words=lines=0
for line in flie:
lines+=1
chars+=len(line)
words+=len([Link]())
[Link]()
print("Lines:",lines)
print("Words:",words)
print("Characters:",chars)

OUTPUT:

19

You might also like