Practical Index Class X
Practical Index Class X
else:
Output:
Code:
per = (marks/450)*100
print("A+")
print("A")
print("B")
print("C")
print("D")
print("E")
else:
print("F")
Output:
Code:
Code:
Code:
for i in range(1,n+1,2):
print(i)
Output:
Code:
sum_of_numbers = 0
sum_of_numbers += i
Output:
Question 8: Create a list num=[23,10,15,90,68,45]
i. Print the length of the list
ii. Print the elements from second to fourth position using positive
indexing
iii. Print the elements from position third to fifth using negative indexing
Code:
num=[23, 10, 15, 90, 68, 45]
print("Length of the list:", len(num))
print("Elements from second to fourth position (using positive
indexing):", num[1:4])
Output:
Question 9: Create a list of first 5 even numbers, add 1 to each list item
and print the final list.
Code:
even_numbers = (2 * i for i in range(1, 6))
final_list = [num + 1 for num in even_numbers]
print(final_list)
Output:
Code:
Code:
list1 = [1, 2, 3, 4, 5]
if len(list1) != len(list2):
result = []
for i in range(len(list1)):
result.append(list1[i] + list2[i])
Output:
Question 12: WAP to calculate mean, median and mode using numpy
Code:
import numpy as np
from scipy import stats
data = [10, 15, 20, 25, 30, 35, 40, 45, 50]
mean = np.mean(data)
median = np.median(data)
mode = stats.mode(data)[0]
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
Output:
Question 13: WAP to display line chart from (2,5) to (9,10)
Code:
x_values = [2, 9]
plt.plot(x_values, y_values)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Chart')
plt.grid(True)
plt.show()
Output:
Question 14: WAP to display a scatter chart for the following points
(2,5), (9,10), (8,3), (5,7), (6,18)
Code:
x_values = [2, 9, 8, 5, 6]
plt.scatter(x_values, y_values)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Chart')
plt.grid(True)
plt.show()
Output: