0% found this document useful (0 votes)
5 views

Python Code - Removed - Merged

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)
5 views

Python Code - Removed - Merged

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/ 31

Name – DAKSH LODHA Class - B.

Tech, III Year Branch - AI &DS, Sem-V


Subject – PROGRAMMING WITH PYTHON AI351(PCC)

Index
Date of Sign/
Sr. Page
Topic
No No. Remarks
Done Checked

Write a program to find the Area and


1 Circumference of a Circle.

Write a program to check number is Even


2 or odd.
Write a program to find the largest
3 among three number.
Write a program to print the Table of a
4 number.
Write a program to print Prime Numbers
5 between 900 to 1000.
Write a program to print right-angled '#’
Pattern.
6
Write a program to display the Fibonacci
7 sequence upto n-th term.
Write a program to check Armstrong
8 numbers in a certain interval.

Write a program to find that the


number is positive or negative using
9 ladder if-else.

Write a program to find that the


number is positive or negative using
10 nested if-else.

Write a program to make a Simple


Calculator.
11
Write a program to display the
powers of2 using anonymous
function
12

Write a program to display the


Fibonacci sequence using
13 Recursion.
Write a program to transpose a matrix using a
nested loop.
14
Write a program to find the Sum
of Natural Numbers using
15 Recursion.

Write a program to import a module.


16
Write a program to mail merge.

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).

Write a program to Split a List into Evenly Sized


Chunks.
20
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)

EXPERIMENT-1

OBJECTIVE:-Write a program to find the Area and Circumference of a Circle.

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

OBJECTIVE- Write a program to check number is Even or Odd.

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

OBJECTIVE–Write a program to find the largest among three number .

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

OBJECTIVE – Write a program to print the Table of a number.

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

OBJECTIVE–Write a program to print Prime Numbers between 900 to 1000.

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

Objective:-Write a program to print right-angled '#’ Pattern.

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

OBJECTIVE:-Write a program to display the Fibonacci sequence upto n-th term.

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

OBJECTIVE:-Write a program to check Armstrong numbers in a certain interval.

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

OBJECTIVE:-Write a program to find that the number is positive or negative


using ladder if-else.

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

OBJECTIVE:-Write a program to find that the number is positive or negative


using nested if-else.

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

OBJECTIVE:-Write a program to make a Simple Calculator.

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)

num2 = float(input("Enter the second number: "))


if choice == '1':

print(num1, "+", num2, "=", add(num1, num2))


elif choice == '2':

print(num1, "-", num2, "=", subtract(num1, num2))


elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
next_calculation = input("Do you want to perform another calculation?
(yes/no): ")
if next_calculation.lower() != 'yes':
break
else:
print("Invalid input. Please enter a valid choice.")
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-12

OBJECTIVE:-Write a program to display the powers of2 using anonymous


function

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

OBJECTIVE:-Write a program to display the Fibonacci sequence using


Recursion.

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

OBJECTIVE:-Write a program to transpose a matrix using a nested loop.

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

OBJECTIVE:-Write a program to find the Sum of Natural Numbers using


Recursion.

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

OBJECTIVE:-Write a program to import a module.

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

OBJECTIVE:-Write a program to mail merge.

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:

with open('body.txt', 'r', encoding='utf-8') as body_file:

body = body_file.read()
for name in names_file:

mail = "Hello " + name.strip() + "\n" + body


with open(name.strip() + ".txt", 'w', encoding='utf-8') as mail_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

OBJECTIVE:-Write a program to find the Size(Resolution)of an Image.

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]

print("The resolution of the image is", width, "x", height)

# 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

OBJECTIVE:-Write a program to catch Multiple Exceptions as a Parenthesized


Tuple(in one line).

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

OBJECTIVE:-Write a program to Split a List into Evenly Sized Chunks.

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]

chunk_size = int(input("Enter the Chunk Size: "))


n = int(input("Enter the number of elements in the List: "))
my_list = []
for i in range(n):
element = int(input("Enter an element: "))
my_list.append(element)
result = list(split(my_list, chunk_size))
print("Split list into chunks:", result)
Name –DAKSH LODHA Class - B. Tech, III Year Branch - AI &DS, Sem-V
SUBJECT- PROGRAMMING WITH PYTHON AI351(PCC)

You might also like