Term
Term
Artificial Intelligence
Practical File
Class: IX-A
Session- 2024-25
List of Codes: -
1. Write a program to find square of number 7: -
# Program to find the square of a number
Number = 7
square = number ** 2
print (f"The square of {number} is {square}")
O/P
The square of 7 is 49
O/P
Enter marks for Subject 1: 85
O/P
for number in range (1, 101, 2): # Start from 1, increment by 2 to get odd
numbers
O/P
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57
59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
return a + b
return a - b
return a * b
if b != 0:
return a / b
else:
# Display menu
print("\nCalculator Menu:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Exit")
if choice == '5':
break
# Input numbers
# Perform operation
if choice == '1':
else:
O/P
Calculator Menu:
1. Add
2. Subtract
3. Multiply
4. Divide
5. Exit
Result: 10 + 5 = 15.0
Calculator Menu:
1. Add
2. Subtract
3. Multiply
4. Divide
5. Exit
days_of_week = {
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
7: "Sunday"
else:
O/P
O/P (case 2)
else:
Enter a number: 8
Enter a number: 7
import math
O/P
speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
# Calculate mean, median, mode, and standard deviation
mean_value = statistics.mean(speed)
median_value = statistics.median(speed)
mode_value = statistics.mode(speed)
std_deviation = statistics.stdev(speed)
print(f"Mean: {mean_value:.2f}")
print(f"Median: {median_value}")
print(f"Mode: {mode_value}")
O/P
Mean: 89.77
Median: 87
Mode: 86
plt.xlabel("Students")
plt.ylabel("Marks")
# Add a title
plt.show()
plt.xlabel("Students")
plt.ylabel("Marks")
plt.grid(True)
plt.legend()
plt.show()
15.
Write a program to draw histogram charts using
matplotlib library: -
import matplotlib.pyplot as plt
marks = [50, 70, 90, 70, 85, 95, 65, 75, 60, 55, 80, 100, 45, 65, 75, 85]
plt.title("Distribution of Marks")
plt.xlabel("Marks Range")
plt.ylabel("Frequency")
plt.show()
16. Create a List in Python of children selected for science quiz with
following
names-Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha and Kartik. Perform
the
following tasks on the list in sequence-
a) Print the whole list
b) Delete the name “Vikram” from the list
c) Add the name “Riya” at the end.
d) Remove the item which is at fourth position.
e) Print the length of the list.
f) Print the elements from second to fourth position using positive
indexing.
g) Reverse the list items.
# Create the initial list
children.append("Riya")
removed_item = children.pop(3)
length = len(children)
sublist = children[1:4]
children.reverse()
O/P
Initial list of children: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
After adding 'Riya': ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Riya']
After removing the fourth item 'Sonal': ['Arjun', 'Sonakshi', 'Sandhya', 'Isha', 'Kartik', 'Riya']