0% found this document useful (0 votes)
2 views18 pages

AI Project File(Rushil Aima)

The document contains a practical file for Class IX Artificial Intelligence, authored by Rushil Aima, featuring 15 programming exercises. Each program addresses a specific task, such as checking for prime numbers, generating Fibonacci series, and calculating simple interest. The file includes the aim, program code, and expected output for each exercise.

Uploaded by

aimarushil007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

AI Project File(Rushil Aima)

The document contains a practical file for Class IX Artificial Intelligence, authored by Rushil Aima, featuring 15 programming exercises. Each program addresses a specific task, such as checking for prime numbers, generating Fibonacci series, and calculating simple interest. The file includes the aim, program code, and expected output for each exercise.

Uploaded by

aimarushil007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

OPG WORLD SCHOOL

CLASS IX

ARTIFICIAL INTELLIGENCE
PRACTICAL FILE

NAME : Rushil Aima


SECTION: B
PROGRAM 1
Aim: To check if the number given by the user is a Prime
Number

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:

nterms = int(input("How many terms? "))


n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1

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

number_to_guess = random.randint(1, 100)


guess = None

print("Guess the number (between 1 and 100):")

while guess != number_to_guess:


guess = int(input("Enter your guess: "))

if guess < number_to_guess:


print("Too low!")
elif guess > number_to_guess:
print("Too high!")
else:
print("Congratulations! You guessed the correct number:
{number_to_guess}")

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: "))

for i in range(1, 11):


print(f"{num} x {i} = {num * i}")
Output:

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: "))

for i in range(1, rows + 1):


for j in range(rows - i):
print(" ", end=" ")
for k in range(2 * i - 1):
print("*", end=" ")
print()

Output:
PROGRAM 8
Aim: To print the sum of digits of a number

Program:
num = int(input("Enter a number: "))
sum = 0

while num > 0:


sum += num % 10
num //= 10

print("The sum of the digits is:" , sum)

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

for char in string:


if char.isalpha():
if char in vowels:
vowel_count += 1
else:
consonant_count += 1

print(f"Vowels: {vowel_count}, Consonants: {consonant_count}")

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: "))

simple_interest = (principal * rate * time) / 100


print(f"The simple interest is: {simple_interest}")

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

while start < end:


lst[start], lst[end] = lst[end], lst[start]
start += 1
end -= 1

print("Reversed list is:", lst)

Output:
PROGRAM 12
Aim: To calculate the sum of natural numbers

Program:
n = int(input("Enter a positive number: "))
sum = 0

for i in range(1, n + 1):


sum += i

print(f"The sum of the first {n} natural numbers is {sum}.")

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

print(f"The smallest number is {smallest}.")

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]

print("Sorted array is:", arr)

Output:

You might also like