Artificial Intelligence
Artificial Intelligence
Practical File
Session: 2024-25
Code:
num1 = int(input("Enter the first
integer: ")) num2 = int(input("Enter the
second integer: ")) print("The sum is:",
num1 + num2)
Code:
num1 = int(input("Enter the first
integer: ")) num2 = int(input("Enter the
second integer: "))
print("The result of subtraction is:", num1 - num2)
Code:
num1 = float(input("Enter the dividend:
")) num2 = float(input("Enter the
divisor: ")) print("The quotient is:",
num1 / num2)
5. Write a program that accepts radius of a circle and prints its area.
Code:
radius = float(input("Enter the radius of the
circle: ")) area = 3.14 * radius ** 2
print("The area of the circle is:", area)
6. Write a program that accepts base and height and calculate the area of the triangle.
Code:
base = float(input("Enter the base of the
triangle: ")) height = float(input("Enter the
height of the triangle: ")) area = 0.5 * base *
height
print("The area of the triangle is:", area)
7. Write a program that inputs a student’s marks in three subjects (out of 100) and prints the
percentage marks.
Code:
marks1 = float(input("Enter marks for the first subject (out of
100): ")) marks2 = float(input("Enter marks for the second subject
(out of 100): ")) marks3 = float(input("Enter marks for the third
subject (out of 100): "))
Code:
side = float(input("Enter the side length of the
square: ")) area = side ** 2
print("The area of the square is:", area)
9. Write a program to input length and breadth and display perimeter of rectangle.
Code:
length = float(input("Enter the length of the
rectangle: ")) breadth = float(input("Enter the
breadth of the rectangle: ")) perimeter = 2 * (length
+ breadth)
print("The perimeter of the rectangle is:", perimeter)
10.Write a program to accept principal, rate and time and calculate simple interest.
Code:
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest (as a
percentage): ")) time = float(input("Enter the time period
(in years): ")) simple_interest = (principal * rate * time) /
100
print("The simple interest is:", simple_interest)
11.Write a program to accept a number and check whether it is even no or odd no.
Code:
number = int(input("Enter a
number: ")) if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
12.Write a program to accept a number and check whether number is positive or negative.
Code:
number = float(input("Enter a
number: ")) if number > 0:
print("The number is
positive.") elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
13.Write a program to accept two numbers and find out greatest out of two numbers.
Code:
num1 = float(input("Enter the first
number: ")) num2 = float(input("Enter the
second number: ")) if num1 > num2:
print("The greatest number is:", num1)
else:
print("The greatest number is:", num2)
14.Write a program to accept two numbers and find out smallest out of two numbers
Code:
num1 = float(input("Enter the first
number: ")) num2 = float(input("Enter the
second number: ")) if num1 < num2:
print("The smallest number is:", num1)
else:
print("The smallest number is:", num2)
15.Write a program to accept three numbers and find out greatest out of two numbers.
Code:
num1 = float(input("Enter the first
number: ")) num2 = float(input("Enter the
second number: ")) num3 =
float(input("Enter the third number: "))
greatest = num1
if num2 > greatest:
greatest =
num2 if num3 >
greatest:
greatest = num3
print("The greatest number is:", greatest)
16.Write a program to accept three numbers and find out smallest out of two numbers.
Code:
num1 = float(input("Enter the first
number: ")) num2 = float(input("Enter the
second number: ")) num3 =
float(input("Enter the third number: "))
smallest = num1
if num2 < smallest:
smallest =
num2 if num3 <
smallest:
smallest = num3
print("The smallest number is:", smallest)
Code:
number = int(input("Enter a
number: ")) for i in range(1, 11):
print(f"{number} x {i} = {number * i}")
18.Write a program to accept a number and calculate its factorial.
Code:
number = int(input("Enter a number: "))
factorial = 1
for i in range(1, number + 1):
factorial *= i
print("The factorial of", number, "is:", factorial)
Code:
for i in range(1,
5): for j in
range(i):
print('*',
end='') print()
Code:
a, b = 0, 1
for _ in range(20):
print(a,
end=' ') a, b
= b, a + b
21.Write a program to display the concept of Series using Pandas.
Code:
import pandas as pd
22.Write a program to display Month name and number of days in that month using Pandas series.
Code:
import pandas as
pd data = {
'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30, 'July': 31, 'August': 31,
'September':
30, 'October': 31, 'November': 30, 'December': 31
}
series = pd.Series(data)
print(series)
23.Write a program to display Name and Marks of your 5 friends using Dataframe.
Code:
import pandas as pd
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David',
'Eve'], 'Marks': [85, 90, 78, 92, 88]
}
df =
pd.DataFrame(data)
print(df)
Code:
import pandas as pd
data = {
'Subject': ['Math', 'Science', 'English', 'History',
'Art'], 'Marks': [95, 88, 76, 85, 90]
}
df =
pd.DataFrame(data)
print(df)
25.Write a program to calculate the statistical values- Mean, Median and Mode using Numpy.
Code:
import numpy as np
data = [10, 20, 20, 30, 40, 50, 60, 70, 80, 90]
mean =
np.mean(data) median
= np.median(data)
mode = np.argmax(np.bincount(data))
print("Mean:", mean)
print("Median:",
median)
print("Mode:", mode)
Code:
import numpy as np
Code:
string = input("Enter a
string: ") print(string[::-1])
28.Write a program to display Salaries and work experience using line chart.
Code:
import matplotlib.pyplot as plt
experience = [1, 2, 3, 4, 5]
salaries = [30000, 35000, 40000, 45000, 50000]
plt.grid(Tru
e)
plt.show()
29.Write a program to display book title and sales using bar chart.