AI Project File(Rushil Aima)
AI Project File(Rushil Aima)
CLASS IX
ARTIFICIAL INTELLIGENCE
PRACTICAL FILE
Program:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if (num % i) == 0:
print( num, "is not a prime number.")
break
else:
print(num ,"is a prime number.")
else:
print(num ,"is not a prime number.")
Output:
PROGRAM 2
Aim: To create the Fibonacci series
Program:
Output:
PROGRAM 3
Aim: To check for Palindromes
Program:
a = input("Enter a word: ")
a = a.lower()
reverse_a = ""
i = len(a) - 1
while i >= 0:
reverse_a += a[i]
i -= 1
if a == reverse_a:
print(a ," is a palindrome.")
else:
print(a ," is not a palindrome.")
Output:
PROGRAM 4
Aim: To make a number guessing game
Program:
import random
Output:
PROGRAM 5
Aim: To generate the multiplication table of the number
given by the user
Program:
num = int(input("Enter a number to display its multiplication table: "))
PROGRAM 6
Aim: To check for the Armstrong Number
(Armstrong number is a number that is equal to the sum of cubes of its digits.)
Program:
num = int(input("Enter a number: "))
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num, "is an Armstrong number.")
else:
print(num ,"is not an Armstrong number.")
Output:
PROGRAM 7
Aim: To print a christmas tree (pyramid)
Program:
rows = int(input("Enter number of rows: "))
Output:
PROGRAM 8
Aim: To print the sum of digits of a number
Program:
num = int(input("Enter a number: "))
sum = 0
Output:
PROGRAM 9
Aim: To count the vowels and constants in a word
Program:
string = input("Enter a string: ").lower()
vowels = 'aeiou'
vowel_count = 0
consonant_count = 0
Output:
PROGRAM 10
Aim: To calculate Simple Interest
Program:
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time in years: "))
Output:
PROGRAM 11
Aim: To reverse a list
Program:
lst = [int(x) for x in input("Enter list elements separated by space: ").split()]
start = 0
end = len(lst) - 1
Output:
PROGRAM 12
Aim: To calculate the sum of natural numbers
Program:
n = int(input("Enter a positive number: "))
sum = 0
Output:
PROGRAM 13
Aim: To find the smallest number in a list
Program:
numbers = [int(x) for x in input("Enter numbers separated by space: ").split()]
smallest = numbers[0]
for num in numbers:
if num < smallest:
smallest = num
Output:
PROGRAM 14
Aim: To check if an alphabet is a vowel or constant
Program:
char = input("Enter a character: ").lower()
if char in 'aeiou':
print(f"{char} is a vowel.")
elif char.isalpha():
print(f"{char} is a consonant.")
else:
print(f"{char} is not a valid alphabet character.")
Output:
PROGRAM 15
Aim: To arrange the characters in a list in ascending order
(Bubble Algorithm)
Program:
arr = [int(x) for x in input("Enter numbers separated by space: ").split()]
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
Output: