Python Code - Removed - Merged
Python Code - Removed - Merged
Index
Date of Sign/
Sr. Page
Topic
No No. Remarks
Done Checked
17
Write a program to find the Size(Resolution)of
an Image.
18
Write a program to catch Multiple
Exceptions as a Parenthesized Tuple(in
19 one line).
EXPERIMENT-1
Code:
print("Daksh Lodha")
radius=int(input("Enter the value of radius:"))
a=float(3.14* radius*radius)
print("Area of the circle:",a)
b=float(2*3.14*radius)
print("Circumference of circle:",b)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-2
Code:
print("Daksh Lodha")
num=int(input("Enter the number:"))
if(num %2==0):
print("Number is even")
else:
print("Number is odd")
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-3
Code:
print("Daksh Lodha")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))
if a > b and a > c:
print("The greatest number is:", a)
elif b > a and b > c:
print("The greatest number is:", b)
elif c > a and c > b:
print("The greatest number is:", c)
else:
print("All the three numbers are equal")
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-4
Code:
print("Daksh Lodha")
num = int(input("Enter the Number: "))
print("Table of:", num)
for i in range(0, 11):
print(num, "*", i, "=", num * i)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-5
Code:
print("Daksh Lodha")
lower = 900
upper = 1000
print("Prime numbers between", lower, "and", upper)
for i in range(lower, upper + 1):
for n in range(2, i):
if i % n == 0:
break
else:
print(i)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-6
Code:
print("Daksh Lodha")
for i in range(1, 10):
for j in range(1, i + 1):
print("*", end="")
print()
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-7
Code:
print("Daksh Lodha")
num = int(input("Enter the number: "))
n1, n2 = 0, 1
c=0
if num <= 0:
print("Please enter a valid number")
elif num == 1:
print("Fibonacci series up to", num, "term:")
print(n1)
else:
print("Fibonacci series up to", num, "terms:")
while c < num:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
c += 1
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-8
Code:
print("Daksh Lodha")
a = 100
b = 2000
print("Armstrong numbers between", a, "and", b, "are:")
for num in range(a, b):
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 1
if num == sum:
print(num)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-9
Code:
print("Daksh Lodha")
num = float(input("Enter the number: "))
if num > 0:
print(num, "is a positive number")
elif num == 0:
print(num, "is a zero integer")
else:
print(num, "is a negative number")
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-10
Code:
print("Daksh Lodha")
num = float(input("Enter the number: "))
if num >= 0:
if num == 0:
print(num, "is a zero integer")
else:
print(num, "is a positive integer")
else:
print(num, "is a negative number")
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-11
Code:
print("Daksh Lodha")
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
while True:
choice = input("Enter the choice (1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter the first number: "))
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-12
Code:
print("Daksh Lodha")
terms = int(input("Number of terms: "))
result = list(map(lambda x: 2**x, range(terms)))
print("The total number of terms are:", terms)
for i in range(terms):
print("2 raised to the power", i, "is", result[i])
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-13
Code:
print("Daksh Lodha")
def recur_fibo(n):
if n <= 1:
return n
else:
return recur_fibo(n - 1) + recur_fibo(n - 2)
nterms = int(input("Enter the number of terms: "))
if nterms <= 0:
print("Invalid!! Please enter a positive integer.")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-14
Code:
print("Daksh Lodha")
X = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print("The matrix is:", X)
result = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
print("The transpose of matrix X is:")
for r in result:
print(r)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-15
Code:
print("Daksh Lodha")
def recur_sum(n):
if n <= 1:
return n
else:
return n + recur_sum(n - 1)
num = int(input("Enter the number: "))
if num < 0:
print("Enter a positive number:")
else:
print("The sum is", recur_sum(num))
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-16
Code:
print("Daksh Lodha")
import math
print("(Importing module) The value of pi =", math.pi)
import math as m
print("(Importing & renaming module) The value of pi =", m.pi)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-17
Code:
print("Daksh Lodha")
# Names are in the file names.txt
# Body of the mail is in body.txt
with open('names.txt', 'r', encoding='utf-8') as names_file:
body = body_file.read()
for name in names_file:
mail_file.write(mail)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-18
Code:
print("Daksh Lodha")
def jpeg_res(filename):
with open(filename, 'rb') as img_file:
img_file.seek(163) # Move to the correct offset for height and width
a = img_file.read(2)
height = (a[0] << 8) + a[1]
a = img_file.read(2)
width = (a[0] << 8) + a[1]
# Example usage
jpeg_res("flowerimage.jpg")
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-19
Code:
print("Daksh Lodha")
string = input("Enter a string: ")
try:
num = int(input("Enter a number: "))
print(string + str(num)) # Convert num to string before concatenation
except (TypeError, ValueError) as e:
print(e)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)
EXPERIMENT-20
Code:
print("Daksh Lodha")
def split(list_a, chunk_size):
for i in range(0, len(list_a), chunk_size):
yield list_a[i:i + chunk_size]