RAINBOW ENGLISH SR. SEC.
SCHOOL
C-3, JANAKPURI
PRACTICAL FILE
ON
ARTIFICIAL INTELLIGENCE
CODE : 417
SESSION : 2025 -26
SUBMITTED BY: SUBMITTED TO:
STUDENT NAME- MAYANK KANDPAL :TEACHER’S NAME
ROLL NO. - 18 : (Ms. JASPREET KAUR)
CLASS & SECTION- 10 C
INDEX
[Link]. Practical Questions
1.) PROGRAM TO ADD TWO NUMBERS
2.) PROGRAM TO FIND MAXIMUM OF TWO NUMBERS
3.) PROGRAM TO CALCULATE SIMPLE INTEREST
4.) PROGRAM TO CALCULATE THE SQUARE ROOT OF THE NUMBER
5.) PROGRAM TOO PRINT ASCII VALUE OF CHARACTER
6.) PROGRAM TO FIND AREA OF A CIRCLE
7.) PROGRAM TO FIND AREA AND PERIMETER OF A RECTANGLE
8.) PROGRAM TO SWAP TWO VARIABLES
9.) PROGRAM TO GENERATE RANDOM NUMBERS
10.) PROGRAM TO CALCULATE COMPOUND INTEREST
11.) PROGRAM TO CALCULATE CELCIUS TO FAHRENHEIT
12.) PROGRAM TO CHECK IF NUMBER IS EVEN OR ODD
13.) PROGRAM TO CHECK NUMBER IS EVEN ODD OR ZERO
14.) PROGRAM TO DISPLAY A CALENDER
15.) PROGRAM TO PLOT A BAR CHART FOR MEDALS
16.) PROGRAM TO DRAW A LINE CHART
17.) PROGRAM TO DRAW SCATTER CHART FOR PRE BOARD EXAM
18.) PROGRAM TO DRAW BAR CHART FOR STUDENT PRESENT
19.) PROGRAM TO DRAW SCATTER CHART FOR GIVEN TABLE
20.) PROGRAM TO DRAW HISTOGRAM FOR AGE GROUPS
I Would like to express my special
thanks and gratitude to our principal
sir Mr. Sourabh Kashyap as well as
my teacher Ms. Jaspreet Kaur who
gave me the golden opportunity to do
this wonderful activities, which also
helped me to knew about so many new
concepts. I am making this project not
only for marks but also to increase my
knowledge.
Q1: Program to Add Two Numbers
CODE:
# Take input from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Calculate sum
sum = num1 + num2
# Display result
print(f"The sum of {num1} and {num2} is {sum}")
OUTPUT:
Enter first number: 10
Enter second number: 20
The sum of 10 and 20 is 30.0
Q2: Program to Find Maximum of Two Numbers
CODE:
# Take input from user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Find maximum
if num1 > num2:
print(f"{num1} is greater than {num2}")
else:
print(f"{num2} is greater than {num1}")
OUTPUT:
Enter first number: 25
Enter second number: 15
25.0 is greater than 15.0
Q3: Program to Calculate Simple Interest
CODE:
# Take input from user
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest (per annum): "))
time = float(input("Enter time period (in years): "))
# Calculate simple interest
simple_interest = (principal * rate * time) / 100
# Display result
print(f"Principal: {principal}")
print(f"Rate: {rate}%")
print(f"Time: {time} years")
print(f"Simple Interest: {simple_interest}")
print(f"Total Amount: {principal + simple_interest}")
OUTPUT:
Enter principal amount: 1000
Enter rate of interest (per annum): 5
Enter time period (in years): 2
Principal: 1000.0
Rate: 5.0%
Time: 2.0 years
Simple Interest: 100.0
Total Amount: 1100.0
Q4: Program to Calculate Square Root of a Number
CODE:
import math
# Take input from user
number = float(input("Enter a number: "))
# Check if number is positive
if number < 0:
print("Cannot calculate square root of negative number")
else:
# Calculate square root
sqrt = [Link](number)
print(f"Square root of {number} is {sqrt}")
OUTPUT:
Enter a number: 16
Square root of 16.0 is 4.0
Q5: Program to Print ASCII Value of a Character
CODE:
# Take input from user
character = input("Enter a character: ")
# Get ASCII value
ascii_value = ord(character)
# Display result
print(f"ASCII value of '{character}' is {ascii_value}")
OUTPUT:
Enter a character: A
ASCII value of 'A' is 65
Q6: Program to Find Area of a Circle
CODE:
import math
# Take input from user
radius = float(input("Enter radius of circle: "))
# Calculate area
area = [Link] * radius * radius
# Display result
print(f"Radius of circle: {radius}")
print(f"Area of circle: {area:.2f} square units")
OUTPUT:
Enter radius of circle: 5
Radius of circle: 5.0
Area of circle: 78.50 square units
Q7: Program to Find Area and Perimeter of a
Rectangle
CODE:
# Take input from user
length = float(input("Enter length of rectangle: "))
width = float(input("Enter width of rectangle: "))
# Calculate area and perimeter
area = length * width
perimeter = 2 * (length + width)
# Display result
print(f"Length: {length}")
print(f"Width: {width}")
print(f"Area of rectangle: {area} square units")
print(f"Perimeter of rectangle: {perimeter} units")
OUTPUT:
Enter length of rectangle: 10
Enter width of rectangle: 5
Length: 10.0
Width: 5.0
Area of rectangle: 50.0 square units
Perimeter of rectangle: 30.0 units
Q8: Program to Swap Two Variables
CODE:
# Method 1: Using temporary variable
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print(f"Before swap: num1 = {num1}, num2 = {num2}")
# Swap using temporary variable
temp = num1
num1 = num2
num2 = temp
print(f"After swap: num1 = {num1}, num2 = {num2}")
OUTPUT:
Enter first number: 10
Enter second number: 20
Before swap: num1 = 10, num2 = 20
After swap: num1 = 20, num2 = 10
Q9: Program to Generate Random Number
CODE:
import random
# Generate random number between 1 and 100
random_number = [Link](1, 100)
print(f"Random number between 1 and 100: {random_number}")
# Generate 5 random numbers
print("\nFive random numbers:")
for i in range(5):
print([Link](1, 50))
OUTPUT:
Random number between 1 and 100: 42
Five random numbers:
23
45
12
67
89
Q10: Program to Calculate Compound Interest
CODE:
# Take input from user
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest (per annum): "))
time = float(input("Enter time period (in years): "))
n = int(input("Enter number of times interest is compounded per year: "))
# Calculate compound interest
amount = principal * (1 + (rate / 100) / n) ** (n * time)
compound_interest = amount - principal
# Display result
print(f"Principal: {principal}")
print(f"Rate: {rate}%")
print(f"Time: {time} years")
print(f"Compound Interest: {compound_interest:.2f}")
print(f"Total Amount: {amount:.2f}")
OUTPUT:
Enter principal amount: 1000
Enter rate of interest (per annum): 5
Enter time period (in years): 2
Enter number of times interest is compounded per year: 4
Principal: 1000.0
Rate: 5.0%
Time: 2.0 years
Compound Interest: 104.89
Total Amount: 1104.89
Q11: Program to Convert Celsius to Fahrenheit
CODE:
# Take input from user
celsius = float(input("Enter temperature in Celsius: "))
# Convert to Fahrenheit
fahrenheit = (celsius * 9/5) + 32
# Display result
print(f"{celsius}°C = {fahrenheit}°F")
OUTPUT:
Enter temperature in Celsius: 25
25.0°C = 77.0°F
Q12: Program to Check Whether Number is Odd or
Even
CODE:
# Take input from user
number = int(input("Enter a number: "))
# Check if number is odd or even
if number % 2 == 0:
print(f"{number} is an even number")
else:
print(f"{number} is an odd number")
OUTPUT:
Enter a number: 7
7 is an odd number
Q13: Program to Check Whether Number is Odd,
Even or Zero
CODE:
# Take input from user
number = int(input("Enter a number: "))
# Check if number is odd, even or zero
if number == 0:
print(f"{number} is zero")
elif number % 2 == 0:
print(f"{number} is an even number")
else:
print(f"{number} is an odd number")
OUTPUT:
Enter a number: 0
0 is zero
Q14: Program to Display a Calendar
CODE:
import calendar
# Take input from user
year = int(input("Enter year: "))
month = int(input("Enter month (1-12): "))
# Display calendar
print(f"\nCalendar for {month}/{year}\n")
print([Link](year, month))
OUTPUT:
Enter year: 2025
Enter month (1-12): 12
Calendar for 12/2025
December 2025
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Q15: Program to Plot a Bar Chart for Medals
CODE:
import [Link] as plt
import numpy as np
# Data for medals
countries = ['India', 'China', 'USA', 'Russia', 'Japan']
gold = [7, 38, 36, 32, 17]
silver = [8, 32, 38, 35, 8]
bronze = [4, 18, 27, 32, 21]
total = [19, 88, 101, 99, 46]
# Create figure
fig, ax = [Link](figsize=(10, 6))
# Set position of bars
x = [Link](len(countries))
width1 = 0.2
width2 = 0.25
width3 = 0.3
width4 = 0.15
# Plot bars with different widths and colors
[Link](x - 1.5*width1, gold, width1, label='Gold', color='#FFD700')
[Link](x - 0.5*width2, silver, width2, label='Silver', color='#C0C0C0')
[Link](x + 0.5*width3, bronze, width3, label='Bronze', color='#CD7F32')
[Link](x + 1.5*width4, total, width4, label='Total', color='#1f77b4')
# Add labels and title
ax.set_xlabel('Countries', fontsize=12, fontweight='bold')
ax.set_ylabel('Number of Medals', fontsize=12, fontweight='bold')
ax.set_title('Olympic Medal Count', fontsize=14, fontweight='bold')
ax.set_xticks(x)
ax.set_xticklabels(countries)
[Link]()
[Link](axis='y', alpha=0.3)
# Display
plt.tight_layout()
[Link]()
OUTPUT:
Q16: Program to Draw a Line Chart
CODE:
import [Link] as plt
# Data from the given table
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales_A = [100, 150, 120, 180, 200, 220]
sales_B = [80, 120, 140, 160, 180, 200]
sales_C = [120, 100, 160, 140, 200, 240]
# Create figure
[Link](figsize=(10, 6))
# Plot lines with different styles and colors
[Link](months, sales_A, marker='o', linewidth=2.5, color='#FF6B6B',
label='Product A', markersize=8)
[Link](months, sales_B, marker='s', linewidth=2, color='#4ECDC4',
label='Product B', markersize=8)
[Link](months, sales_C, marker='^', linewidth=1.5, color='#FFE66D',
label='Product C', markersize=8)
# Add labels and title
[Link]('Months', fontsize=12, fontweight='bold')
[Link]('Sales (Units)', fontsize=12, fontweight='bold')
[Link]('Monthly Sales Comparison', fontsize=14, fontweight='bold')
[Link](loc='best', fontsize=10)
[Link](True, alpha=0.3)
# Display
plt.tight_layout()
[Link]()
OUTPUT:
Q17: Program to Draw Scatter Chart for Pre-Board
and Board Exams
CODE:
import [Link] as plt
import numpy as np
# Data for 10 students
students = ['Student 1', 'Student 2', 'Student 3', 'Student 4', 'Student 5',
'Student 6', 'Student 7', 'Student 8', 'Student 9', 'Student 10']
preboard_marks = [72, 85, 68, 92, 78, 88, 95, 65, 80, 75]
board_marks = [75, 88, 70, 94, 80, 90, 98, 68, 82, 78]
# Create scatter plot
[Link](figsize=(10, 6))
[Link](preboard_marks, board_marks, color='#FF6B6B', s=100, alpha=0.6,
edgecolors='black')
# Add labels and title
[Link]('Pre-Board Exam Marks (out of 100)', fontsize=12,
fontweight='bold')
[Link]('Board Exam Marks (out of 100)', fontsize=12, fontweight='bold')
[Link]('Pre-Board vs Board Exam Performance', fontsize=14,
fontweight='bold')
[Link](True, alpha=0.3)
# Add reference line
[Link]([60, 100], [60, 100], 'k--', alpha=0.3, label='Perfect Match')
[Link]()
# Display
plt.tight_layout()
[Link]()
OUTPUT:
Q18: Program to Draw Bar Chart for Students
Present in Each Class
CODE:
import [Link] as plt
# Data for students in each class
classes = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X']
total_students = [45, 42, 48, 50, 46, 44, 47, 49, 51, 52]
present_students = [43, 40, 46, 48, 44, 42, 45, 47, 49, 50]
# Create bar chart
fig, ax = [Link](figsize=(12, 6))
x = range(len(classes))
width = 0.35
bars1 = [Link]([i - width/2 for i in x], total_students, width,
label='Total Students', color='#87CEEB')
bars2 = [Link]([i + width/2 for i in x], present_students, width,
label='Present Students', color='#90EE90')
# Add labels and title
ax.set_xlabel('Classes', fontsize=12, fontweight='bold')
ax.set_ylabel('Number of Students', fontsize=12, fontweight='bold')
ax.set_title('Student Attendance by Class', fontsize=14, fontweight='bold')
ax.set_xticks(x)
ax.set_xticklabels(classes)
[Link]()
[Link](axis='y', alpha=0.3)
# Display
plt.tight_layout()
[Link]()
OUTPUT:
Q19: Program to Draw Scatter Chart for Given Table
CODE:
import [Link] as plt
# Data from the given table (Height vs Weight)
height = [150, 155, 160, 165, 170, 172, 175, 180, 185, 190]
weight = [45, 50, 55, 60, 65, 68, 72, 75, 80, 85]
# Create scatter plot
[Link](figsize=(10, 6))
[Link](height, weight, color='#9B59B6', s=120, alpha=0.7,
edgecolors='black', linewidth=1.5)
# Add labels and title
[Link]('Height (cm)', fontsize=12, fontweight='bold')
[Link]('Weight (kg)', fontsize=12, fontweight='bold')
[Link]('Relationship between Height and Weight', fontsize=14,
fontweight='bold')
[Link](True, alpha=0.3)
# Display
plt.tight_layout()
[Link]()
OUTPUT:
Q20: Program to Draw Histogram for Age Groups
CODE:
import [Link] as plt
import numpy as np
# Generate random age data for 50 people
[Link](42)
ages = [Link](loc=35, scale=15, size=50).astype(int)
ages = [Link](ages, 10, 80) # Clip ages between 10 and 80
# Create histogram
[Link](figsize=(10, 6))
n, bins, patches = [Link](ages, bins=10, color='#3498DB',
edgecolor='black', alpha=0.7)
# Add labels and title
[Link]('Age Groups', fontsize=12, fontweight='bold')
[Link]('Number of People', fontsize=12, fontweight='bold')
[Link]('Distribution of Age Groups (50 People)', fontsize=14,
fontweight='bold')
[Link](axis='y', alpha=0.3)
# Add value labels on bars
for i, v in enumerate(n):
[Link](bins[i] + (bins[1]-bins[0])/2, v + 0.2, str(int(v)),
ha='center', va='bottom', fontweight='bold')
# Display
plt.tight_layout()
[Link]()
OUTPUT: