Class 10 AI Practiacls 2023-24

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Class 10 AI Practical’s

1. Write a program to count the number of even and odd numbers in a series of numbers using for
loop
Ans.
numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple
count_odd = 0
count_even = 0
for x in numbers:
if not x % 2:
count_even+=1
else:
count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)

2. Write a program to print the following half-pyramid pattern of numbers. (Use for Loop)

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Ans.

rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=' ')
print('')

3. Write a program to print pyramid and Star (asterisk) patterns in Python.


*

* *

* * *

* * * *

* * * * *

Ans.
# number of rows
rows = 5
for i in range(0, rows):
# nested loop for each column
for j in range(0, i + 1):
# print star
print("*", end=' ')
# new line after each row
print("\r")

4. Write a program to add the elements of the two lists.


Ans.
List1 = [7, 5.7, 21, 18, 8/3]
List2 = [9, 15, 6.2, 1/3,11]
# printing original lists
print ("list1 : " + str(List1))
print ("list2 : " + str(List2))
newList = []
for n in range(0, len(List1)):
newList.append(List1[n] + List2[n])
print(newList)

5. Write a program to calculate mean, median and mode using Numpy


Ans.
import numpy as np
array = np.arange(20)
print(array)
r1 = np.mean(array)
print("\nMean: ", r1)
r1 = np.median(array)
print("\nstd: ", r1)
r1 = np.std(array)
print("\nstd: ", r1)

6. Write a Python program to draw a line with suitable label in the x axis, y axis and a title
Ans.
import matplotlib.pyplot as plt
X = range(1, 50)
Y = [value * 3 for value in X]
print("Values of X:")
print(*range(1,50))
print("Values of Y (thrice of X):")
print(Y)
# Plot lines and/or markers to the Axes.
plt.plot(X, Y)
# Set the x axis label of the current axis.
plt.xlabel('x - axis')
# Set the y axis label of the current axis.
plt.ylabel('y - axis')
# Set a title
plt.title('Draw a line.')
# Display the figure.
plt.show()
7. Write a Python program to draw a scatter plot comparing two subject marks of Mathematics
and Science. Use marks of 10 students.
Sample data:

Test Data:
math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

Ans.
import matplotlib.pyplot as plt
import pandas as pd
math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
plt.scatter(marks_range, math_marks, label='Math marks', color='r')
plt.scatter(marks_range, science_marks, label='Science marks', color='g')
plt.title('Scatter Plot')
plt.xlabel('Marks Range')
plt.ylabel('Marks Scored')
plt.legend()
plt.show()

8. Write a Pandas program to read a csv file from a specified source and print the first 5 rows.
Ans.
import pandas as pd
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 50)
diamonds = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-
data/master/diamonds.csv')
print("First 5 rows:")
print(diamonds.head())

9. Write a program to count number of records present in “data.csv” file.

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