0% found this document useful (0 votes)
6 views12 pages

Add A Heading

The document contains a series of Python programs demonstrating various functionalities including character checks, maximum number calculations, electric power distribution charges, Armstrong number checks, and generating multiplication tables. It also includes programs for creating 2D arrays with NumPy, visualizing data with Matplotlib, calculating statistics, reading CSV files, and performing image processing tasks with OpenCV. Each program is presented with code snippets and brief descriptions of their purpose.

Uploaded by

parth170309
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)
6 views12 pages

Add A Heading

The document contains a series of Python programs demonstrating various functionalities including character checks, maximum number calculations, electric power distribution charges, Armstrong number checks, and generating multiplication tables. It also includes programs for creating 2D arrays with NumPy, visualizing data with Matplotlib, calculating statistics, reading CSV files, and performing image processing tasks with OpenCV. Each program is presented with code snippets and brief descriptions of their purpose.

Uploaded by

parth170309
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/ 12

PRACTICAL

FILE
FOR AI
PARTH PARATE
CLASS 10 B
ROLL NO. 26
1. Program to Check
Uppercase, Lowercase, Digit,
or Special Character
char = input("Enter a character: ")
if char.isupper():
print(f"{char} is an uppercase letter.")
elif char.islower():
print(f"{char} is a lowercase letter.")
elif char.isdigit():
print(f"{char} is a digit.")
else:
print(f"{char} is a special character.")
2. Program to Find
Maximum of Three
Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

maximum = max(a, b, c)
print("The maximum number is”, maximum)
3. Program for Electric
Power Distribution
Charges
customer_number = input("Enter customer
number: ")
units_consumed = float(input("Enter power
consumed in units: "))

if units_consumed <= 100:


amount = units_consumed * 1
elif 101 <= units_consumed <= 300:
amount = 100 + (units_consumed - 100) * 1.25
elif 301 <= units_consumed <= 500:
amount = 350 + (units_consumed - 300) * 1.5
else:
amount = 650 + (units_consumed - 500) * 1.75

print(f"Customer Number: {customer_number}")


print(f"Power Consumed: {units_consumed}
units")
print(f"Amount to be paid: Rs. {amount:.2f}")
4. Program to Check
Armstrong Number
num = int(input("Enter a number: "))
order = len(str(num))
sum = 0
temp = num

while temp > 0:


digit = temp % 10
sum += digit ** order
temp //= 10

if sum == num:
print(f"{num} is an Armstrong number.")
else:
print(f"{num} is not an Armstrong
number.")
5. Program to Print
Multiplication Table
num = int(input("Enter a number: "))

for i in range(1, 11):


print(f"{num} x {i} = {num * i}")

6. Program to Generate
the Pattern
n=5
num = 1
for i in range(1, n + 1):
for j in range(i):
print(num, end=" ")
num += 1
print()
7. Program to Find Maximum
in a List of Students' Marks
marks = [int(input(f"Enter marks for
student {i + 1}: ")) for i in range(5)]
print(f"The maximum marks obtained is:
{max(marks)}")

8. Program to Create a 2D
Array Using NumPy
import numpy as np

rows = int(input("Enter the number of


rows: "))
cols = int(input("Enter the number of
columns: "))
array = np.zeros((rows, cols))

print("2D Array:")
print(array)
9. Program to Convert a
Python List to a NumPy Array
import numpy as np

list1 = [1, 2, 3, 4, 5]
array1 = np.array(list1)
print(f"NumPy array: {array1}")

10. Program to Create a


Matrix of 3×3 with Values
from 11 to 30
import numpy as np

matrix = np.arange(11, 30).reshape(3, 3)


print("Matrix of 3x3:")
print(matrix)
11. Program to Represent
Data on Ratings of Mobile
Games in a Bar Chart
import matplotlib.pyplot as plt

games = ['Pubg', 'FreeFire', 'MineCraft',


'GTA-V', 'Call of duty', 'FIFA 22']
ratings = [4.5, 4.8, 4.7, 4.6, 4.1, 4.3]

plt.bar(games, ratings)
plt.xlabel('Games')
plt.ylabel('Ratings')
plt.title('Ratings of Mobile Games')
plt.show()
12. Program to Plot Data on
Clothes Store Sales in Line
Chart
import matplotlib.pyplot as plt

months = ['March', 'April', 'May', 'June', 'July',


'August']
jeans = [1500, 3500, 6500, 6700, 6000, 6800]
t_shirts = [4400, 4500, 5500, 6000, 5600, 6300]
shirts = [6500, 5000, 5800, 6300, 6200, 4500]

plt.plot(months, jeans, label='Jeans')


plt.plot(months, t_shirts, label='T-Shirts')
plt.plot(months, shirts, label='Shirts')

plt.xlabel('Months')
plt.ylabel('Sales')
plt.title('Clothes Store Sales')
plt.legend()
plt.show()
13. Program to
Calculate Mean, Mode,
and Median
import statistics

data = [5, 6, 1, 3, 4, 5, 6, 2, 7, 8, 6, 5, 4, 6, 5, 1, 2,
3, 4]

mean = statistics.mean(data)
mode = statistics.mode(data)
median = statistics.median(data)

print(f"Mean: {mean}")
print(f"Mode: {mode}")
print(f"Median: {median}")
14. Program to Read
CSV File and Display
10 Rows
import csv

filename = input("Enter the CSV file path: ")

with open(filename, 'r') as file:


reader = csv.reader(file)
for i, row in enumerate(reader):
if i < 10:
print(row)
else:
break
15. Do the Following Tasks in OpenCV
# 1) Load an image
image = cv2.imread('image.jpg')

# 2) Give the title of the image


cv2.imshow("Image Title", image)

# 3) Change the colour of the image (to grayscale)


gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 4) Change the image to grayscale


cv2.imshow("Grayscale Image", gray_image)

# 5) Print the shape of image


print("Shape of the image:", image.shape)

# 6) Display the maximum and minimum pixels of image


print("Max pixel value:", image.max())
print("Min pixel value:", image.min())

# 7) Crop the image (for example, 100x100 region)


cropped_image = image[50:150, 50:150]
cv2.imshow("Cropped Image", cropped_image)

# 8) Extract part of an image (similar to cropping)


extracted_part = image[100:200, 100:200]
cv2.imshow("Extracted Part", extracted_part)

# 9) Resize the image


resized_image = cv2.resize(image, (400, 400))
cv2.imshow("Resized Image", resized_image)

# 10) Save the Image


cv2.imwrite('output_image.jpg', image

You might also like