Artificial Intelligence
Practical File
2024-25
Made By:
Tanmay Sinha
10-C
1
INDEX
S No. Program Title Teacher’s Signature
1. Python program to check wheth
2. Python program to convert centrigade to farenheit
3 Python program to find an average of a set of numbers
4 Python program to find the product of a set of real numbers
5 Python program to find area of circle with given radius
6 python program to check whether integer is multiple of both 5 and 7
7 python program to display integers in reversed manner
8 Python program to display all the integers of 3 within range 10 and 50
9 Python program to check whether the given integer is a prime number or not
10 Python program to find a number in a list
11 . Python Program to Find the Factorial of a Number
12 Python Program to Check Armstrong Number
13 Printing the number elements of a List
14 Program to accessing elements of a list using loops
15
2
INDEX
S.No. Program Title Teacher’s Signature
16 Printing the string elements of a List
17 Program to accessing elements of a
list using loops
18 Different Functions of Numpy
19 Program to create NumPy Array
20 Program to make bar chart using
pandas and matplotlib libraries
3
Python program to check whether the given number is even or not.
number = input("Enter a number: ")
x = int(number)%2
if x == 0:
print("The number is Even.")
else:
print("The number is Odd.")
Output:
Enter a number: 7
The number is Odd.
Enter a number: 6
The number is Even.
Python program to convert the temperature in degree centigrade to
Fahrenheit
c = input("Enter temperature in Centigrade: ")
f = (9*(int(c))/5)+32
print("Temperature in Fahrenheit is: ", f)
Output:
Enter temperature in Centigrade: 30
Temperature in Fahrenheit is: 86.0
Python program to find out the average of a set of integers
count = int(input("Enter the count of numbers:
"))
i=0
sum = 0
for i in range(count):
x = int(input("Enter an integer: "))
sum = sum + x
avg = sum/count
print("The average is: ", avg)
Output:
Enter the count of numbers: 5
Enter an integer: 3
Enter an integer: 6
Enter an integer: 8
Enter an integer: 5
Enter an integer: 7
The average is: 5.8
Python program to find the product of a set of real numbers
i=0
product = 1
count = int(input("Enter the number of real
numbers: "))
for i in range(count):
x = float(input("Enter a real number: "))
product = product * x
print("The product of the numbers is: ",
product)
Output:
Enter the number of real numbers: 4
Enter a real number: 3.2
Enter a real number: 2.9
Enter a real number: 7.4
Enter a real number: 5.5
The product of the numbers is: 377.69599999999997
Python program to find the circumference and area of a circle with a
given radius
r = float(input("Input the radius of the circle: "))
c = 2 * 3.14 * r
area = 3.14 * r * r
print("The circumference of the circle is: ", c)
print("The area of the circle is: ", area)
Output:
Input the radius of the circle: 7
The circumference of the circle is: 43.96
The area of the circle is: 153.86
Python program to check whether the given integer is a multiple of
both 5 and 7
number = int(input("Enter an integer: "))
if((number%5==0)and(number%7==0)):
print(number, "is a multiple of both 5 and 7")
else:
print(number, "is not a multiple of both 5 and 7")
Output:
Enter an integer: 33
33 is not a multiple of both 5 and 7
Python program to display the given integer in a reverse manner
number = int(input("Enter a positive integer: "))
rev = 0
while(number!=0):
digit = number%10
rev = (rev*10)+digit
number = number//10
print(rev)
Output:
Enter a positive integer: 739
937
Python program to display all the multiples of 3 within the range 10 to
50
for i in range(10,50):
if (i%3==0):
print(i)
12
Output: 15
18
21
24
27
30
33
36
39
42
45
48
Python program to check whether the given integer is a prime number
or not
num = int(input("Enter an integer greater than 1: "))
isprime = 1 #assuming that num is prime
for i in range(2,num//2):
if (num%i==0):
isprime = 0
break
if(isprime==1):
print(num, "is a prime number")
else:
print(num, "is not a prime number")
Output:
Enter an integer greater than 1: 7
7 is a prime number
Python program to find a number in a list
numbers = [4,2,7,1,8,3,6]
f = 0 #flag
x = int(input("Enter the number to be found out: "))
for i in range(len(numbers)):
if (x==numbers[i]):
print("Successful search, the element is found at position", i)
f=1
break
if(f==0):
print("Oops! Search unsuccessful")
Output:
Enter the number to be found out: 7
Successful search, the element is found at position 2
Python Program to Find the Factorial of a Number
num = 7
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:
The factorial of 7 is 5040
Python Program to Check Armstrong Number
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output:
Enter a number: 663
663 is not an Armstrong number
Printing the number elements of a List
• # declaring list with integer elements
• list1 = [10, 20, 30, 40, 50]
• # printing list1
• print("List element are: ", list1)
• # printing elements of list1 by index Output
• print("Element @ 0 index:", list1[0]) List element are: [10, 20, 30, 40, 50]
Element @ 0 index: 10
• print("Element @ 1 index:", list1[1])
Element @ 1 index: 20
• print("Element @ 2 index:", list1[2]) Element @ 2 index: 30
• print("Element @ 3 index:", list1[3]) Element @ 3 index: 40
Element @ 4 index: 50
• print("Element @ 4 index:", list1[4])
16
Printing the string elements of a List
• # declaring list with string elements
• list2 = ["New Delhi", "Mumbai", "Chennai", "calcutta"]
• # printing list2
• print("List elements are: ", list2)
• #printing elements of list2 by index Output
• print("Element @ 0 index:",list2 [0]) List elements are: ['New Delhi', 'Mumbai', 'Chennai', 'calcutta']
Element @ 0 index: New Delhi
• print("Element @ 1 index:",list2 [1])
Element @ 1 index: Mumbai
• print("Element @ 2 index:",list2 [2]) Element @ 2 index: Chennai
• print("Element @ 3 index:",list2 [3]) Element @ 3 index: calcutta
• print() # prints new line
17
Program to accessing elements of a list using loops
a= [32,55,7,12,65,32,90,27,12]
for i in a:
print(i)
Output
32
55
7
12
65
32
90
27
12
18
Different Functions of Numpy
import numpy as np
# Creating array object
arr = np.array( [[ 1, 2, 3],
[ 4, 2, 5]] )
Output:
# Printing type of arr object
print("Array is of type: ", type(arr)) Array is of type: <class 'numpy.ndarray'>
# Printing array dimensions (axes) No. of dimensions: 2
print("No. of dimensions: ", arr.ndim) Shape of array: (2, 3)
# Printing shape of array Size of array: 6
print("Shape of array: ", arr.shape)
Array stores elements of type: int64
# Printing size (total number of elements) of array
print("Size of array: ", arr.size)
# Printing type of elements in array
print("Array stores elements of type: ", arr.dtype) 19
Program to create NumPy Array
import numpy as np
Output:
# Creating array from list with type float
a = np.array([[1, 2, 4], [5, 8, 7]], dtype = 'float') Array created using passed list:
print ("Array created using passed list:\n", a) [[1. 2. 4.]
[5. 8. 7.]]
# Creating array from tuple
b = np.array((1 , 3, 2)) Array created using passed tuple:
print ("\nArray created using passed tuple:\n", b) [1 3 2]
20
Program to make bar chart using pandas and matplotlib libraries
import pandas as pd
import matplotlib.pyplot as plot
# A python dictionary
data = {"City":["London", "Paris", "Rome"],
"Visits":[20.42,17.95,9.7] };
# Dictionary loaded into a DataFrame
dataFrame = pd.DataFrame(data=data);
# Draw a vertical bar chart
dataFrame.plot.bar(x="City", y="Visits", rot=70,
title="Number of tourist visits - Year 2018");
plot.show(block=True);
21