0% found this document useful (0 votes)
3 views13 pages

Grade 10 AI Practical File With Solutions (HIBA KHAN - 10F)

The document contains a Grade 10 AI Practical File with various Python programming exercises and solutions. It includes programs for checking even/odd numbers, calculating profit/loss, performing arithmetic operations, and data science tasks like calculating mean, mode, median, variance, and standard deviation. Additionally, it covers data visualization techniques using matplotlib and image processing tasks using OpenCV.

Uploaded by

Hiba Yusuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Grade 10 AI Practical File With Solutions (HIBA KHAN - 10F)

The document contains a Grade 10 AI Practical File with various Python programming exercises and solutions. It includes programs for checking even/odd numbers, calculating profit/loss, performing arithmetic operations, and data science tasks like calculating mean, mode, median, variance, and standard deviation. Additionally, it covers data visualization techniques using matplotlib and image processing tasks using OpenCV.

Uploaded by

Hiba Yusuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Grade 10 AI Practical File with Solutions (HIBA

KHAN - 10F)

1. Write a Python program to check whether the given number


is even or odd.

```python
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
```

2. Write a Python program to calculate the profit or loss by


taking the cost price and selling price as inputs.
Code
```python
cost_price = float(input("Enter the cost price: "))
selling_price = float(input("Enter the selling price: "))
if selling_price > cost_price:
print(f"Profit = {selling_price - cost_price}")
elif cost_price > selling_price:
print(f"Loss = {cost_price - selling_price}")
else:
print("No profit, no loss.")
```

3.Write a Python program to check whether the number is


negative, zero, or positive.
Code:
```python
num = float(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
```

4. Write a menu-driven program for a calculator with


options: Addition, Subtraction, Division, and
Multiplication.
Code:
```python
print("Calculator Menu")
print("1. Addition")
print("2. Subtraction")
print("3. Division")
print("4. Multiplication")

choice = int(input("Enter your choice (1-4): "))


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == 1:
print(f"Result: {num1 + num2}")
elif choice == 2:
print(f"Result: {num1 - num2}")
elif choice == 3:
if num2 != 0:
print(f"Result: {num1 / num2}")
else:
print("Division by zero is not allowed.")
elif choice == 4:
print(f"Result: {num1 * num2}")
else:
print("Invalid choice.")
```

5. Write a Python program to input salary and calculate the


commission for a salesman based on salary slabs.
Code:
```python
salary = float(input("Enter the salary: "))

if salary >= 30001:


commission = 0.15 * salary
elif 22001 <= salary <= 30000:
commission = 0.10 * salary
elif 12001 <= salary <= 22000:
commission = 0.07 * salary
elif 5001 <= salary <= 12000:
commission = 0.03 * salary
else:
commission = 0

print(f"The commission is: {commission}")


```

6. Write a Python program to print the first 10 natural


numbers using `for` and `while` loops.
Code (using for loop):
```python
print("First 10 natural numbers using for loop:")
for i in range(1, 11):
print(i, end=" ")
print()
```
Code (using while loop):
```python
print("First 10 natural numbers using while loop:")
i = 1
while i <= 10:
print(i, end=" ")
i += 1
print()
```

7. Write a Python program to print the sum of the first 10


natural numbers.
Code:
```python
sum = 0
for i in range(1, 11):
sum += i
print(f"The sum of the first 10 natural numbers is:
{sum}")
```

8. Write a Python program to display even numbers between 1


to 100.
Code:
```python
print("Even numbers between 1 and 100:")
for i in range(1, 101):
if i % 2 == 0:
print(i, end=" ")
print()
```

9. Write a Python program to display odd numbers between 1


to 100.
Code:
```python
print("Odd numbers between 1 and 100:")
for i in range(1, 101):
if i % 2 != 0:
print(i, end=" ")
print()
```

10. Write a Python program to display the sum of even


numbers from 100 to 200 (including 200).
Code:
```python
sum = 0
for i in range(100, 201):
if i % 2 == 0:
sum += i
print(f"The sum of even numbers from 100 to 200 is:
{sum}")
```
DATA SCIENCE
Statistical Learning

1.Write a menu-driven Python program to calculate the mean,


mode, and median for the given data:
Data: `[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]`
Code:
```python
import statistics

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

while True:
print("\nMenu:")
print("1. Calculate Mean")
print("2. Calculate Mode")
print("3. Calculate Median")
print("4. Exit")

choice = int(input("Enter your choice (1-4): "))


if choice == 1:
mean = statistics.mean(data)
print(f"Mean: {mean}")
elif choice == 2:
mode = statistics.mode(data)
print(f"Mode: {mode}")
elif choice == 3:
median = statistics.median(data)
print(f"Median: {median}")
elif choice == 4:
break
else:
print("Invalid choice.")
```
2. Write a menu-driven Python program to calculate variance
and standard deviation for the given data:

Data:`[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55
,87]`
Code:
```python
import statistics

data =
[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

while True:
print("\nMenu:")
print("1. Calculate Variance")
print("2. Calculate Standard Deviation")
print("3. Exit")

choice = int(input("Enter your choice (1-3): "))


if choice == 1:
variance = statistics.variance(data)
print(f"Variance: {variance}")
elif choice == 2:
std_dev = statistics.stdev(data)
print(f"Standard Deviation: {std_dev}")
elif choice == 3:
break
else:
print("Invalid choice.")
```

---

Data Visualization

3. Write a Python program to represent the ratings of


programming languages on a bar graph.
Data: Languages: `Java, Python, C++, C, PHP`;
Ratings: `4.5, 4.8, 4.7, 4.6, 4.3`.
Code:
```python
import matplotlib.pyplot as plt

languages = ['Java', 'Python', 'C++', 'C', 'PHP']


ratings = [4.5, 4.8, 4.7, 4.6, 4.3]

plt.bar(languages, ratings)
plt.title("Programming Language Ratings")
plt.xlabel("Languages")
plt.ylabel("Ratings")
plt.show()
```

4. Write a Python program to plot the monthly sales of a


salesman on a line chart.
Data: Months: `Jan, Feb, Mar, Apr, May, Jun`;
Sales: `2500, 2100, 1700, 3500, 3000, 3800`.
Code:
```python
import matplotlib.pyplot as plt

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']


sales = [2500, 2100, 1700, 3500, 3000, 3800]

plt.plot(months, sales, color='red', marker='o',


markerfacecolor='black')
plt.title("Sales Stats")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.legend(["Monthly Sales"])
plt.show()
```

5. Write a Python program to print stream-wise admissions in


a pie chart.
Data : Civil: `15`, Electrical: `35`, Mechanical: `40`,
Chemical: `20`, CS: `50` (with wedge for CS).
Code:
```python
import matplotlib.pyplot as plt

streams = ['Civil', 'Electrical', 'Mechanical',


'Chemical', 'Computer Science']
admissions = [15, 35, 40, 20, 50]

plt.pie(admissions, labels=streams, autopct='%1.1f%%',


startangle=90, wedgeprops={'edgecolor': 'black'},
explode=[0, 0, 0, 0, 0.1])
plt.title("Stream-wise Admissions")
plt.show()
```

6. Write a Python program to create a boxplot for marks in


different subjects.
Data : Math: `[74.5, 76.5, 95, 86]`; Science: `[89, 95,
79, 92]`; SST: `[87, 91, 82, 72]`.
Code:
```python
import matplotlib.pyplot as plt

data = {
'Maths': [74.5, 76.5, 95, 86],
'Science': [89, 95, 79, 92],
'SST': [87, 91, 82, 72]
}

plt.boxplot(data.values(), labels=data.keys())
plt.title("Boxplot of Marks")
plt.ylabel("Marks")
plt.show()
```
7. Write a Python program to construct a scatter plot for
height and weight of students.
Data: Heights: `[120, 145, 130, 155, 160, 135, 150, 145,
130, 140]`; Weights: `[40, 50, 47, 62, 60, 55, 58, 52,
50, 49]`.
Code:
```python
import matplotlib.pyplot as plt

height = [120, 145, 130, 155, 160, 135, 150, 145, 130,
140]
weight = [40, 50, 47, 62, 60, 55, 58, 52, 50, 49]

plt.scatter(height, weight)
plt.title("Height vs Weight")
plt.xlabel("Height (cm)")
plt.ylabel("Weight (kg)")
plt.show()
```

8. Write a Python program to plot a histogram for marks of


students.
Data: Marks: `[22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51,
5, 79, 31, 27]`.
Code:
```python
import matplotlib.pyplot as plt

marks = [22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5,
79, 31, 27]

plt.hist(marks, bins=5, edgecolor='black')


plt.title("Histogram of Marks")
plt.xlabel("Marks")
plt.ylabel("Frequency")
plt.show()
```
Here’s the transcription for **Grade 10 AI CV Programs**
with questions and Python code answers:

---

Grade 10 AI CV Programs

1. Write a Python program to load the JPG image of any


personality.
Code :
```python
import cv2

# Load an image
image = cv2.imread('personality.jpg')
cv2.imshow('Personality Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
```

2. Write a Python program to convert a BGR image to RGB


format.
Code:
```python
import cv2

# Load an image in BGR format


image = cv2.imread('personality.jpg')
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

print("Converted to RGB format.")


```

3. Write a Python program to convert a color image into


grayscale.
Code:
```python
import cv2
# Load a color image
image = cv2.imread('personality.jpg')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow('Grayscale Image', gray_image)


cv2.waitKey(0)
cv2.destroyAllWindows()
```

4. Write a Python program to find the size of a color image.


Code:
```python
import cv2

# Load an image
image = cv2.imread('personality.jpg')
print(f"Image dimensions: {image.shape}")
```

5. Write a Python program to find the minimum and maximum


pixel values in an image.
Code:
```python
import cv2
import numpy as np

# Load an image
image = cv2.imread('personality.jpg',
cv2.IMREAD_GRAYSCALE)
min_val = np.min(image)
max_val = np.max(image)

print(f"Minimum pixel value: {min_val}")


print(f"Maximum pixel value: {max_val}")
```
6. Write a Python program to find the Region of Interest
(ROI) and crop the image.
Code:
```python
import cv2

# Load an image
image = cv2.imread('personality.jpg')

# Define ROI (example: x=50, y=50, width=200, height=200)


roi = image[50:250, 50:250]

cv2.imshow('Cropped Image', roi)


cv2.waitKey(0)
cv2.destroyAllWindows()
```

7. Write a Python program to extract a portion of an image.


Code:
*(This overlaps with the ROI cropping as it extracts a
defined region.)*
```python
import cv2

# Load an image
image = cv2.imread('personality.jpg')

# Extract a portion (example: x=100, y=100, width=150,


height=150)
portion = image[100:250, 100:250]

cv2.imshow('Extracted Portion', portion)


cv2.waitKey(0)
cv2.destroyAllWindows()
```

8. Write a Python program to resize and save the image.


Code:
```python
import cv2

# Load an image
image = cv2.imread('personality.jpg')

# Resize the image (e.g., to 200x200)


resized_image = cv2.resize(image, (200, 200))

# Save the resized image


cv2.imwrite('resized_personality.jpg', resized_image)
print("Image resized and saved.")
```

---

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy