OPG WORLD SCHOOL
CLASS IX
ARTIFICIAL INTELLIGENCE
PRACTICAL FILE
NAME : EESHAAN CHHABRA
SECTION: IX-B
PROGRAM 1
AIM: To add two numbers taken by user.
PROGRAM:
n = int(input("number 1 :"))
m = int(input("number 2 :"))
print(n+m)
OUTPUT:
PROGRAM 2
AIM: To find the square root of a number
PROGRAM:
n = int(input("number :"))
x = n ** 0.5
print(x)
OUTPUT:
PROGRAM 3
AIM: To find the area of a triangle
PROGRAM:
a = float(input("Side 1 :"))
b = float(input("Side 2 :"))
c = float(input("Side 3 :"))
s = (a+b+c)/2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print(area)
OUTPUT:
PROGRAM 4
AIM: To identify odd and even number
PROGRAM:
n = int(input("number :"))
if n%2 == 0:
print("Even")
else:
print("Odd")
OUTPUT:
PROGRAM 5
AIM: To identify prime numbers
PROGRAM:
l = int(input("number 1 :"))
u = int(input("number 2 :"))
print("Prime numbers between", l, "and", u, "are:")
for num in range(l, u + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
OUTPUT:
PROGRAM 6
AIM: Convert Celsius into Fahrenheit
PROGRAM:
c = int(input("Celcius :"))
f = (c * 1.8) + 32
print(f)
OUTPUT:
PROGRAM 7
AIM: To display multiplication table
PROGRAM:
num = int(input("Display multiplication table of? "))
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
OUTPUT:
PROGRAM 8
AIM: To find factors of a number
PROGRAM:
def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
num = int(input("Number :"))
print_factors(num)
OUTPUT:
PROGRAM 9
AIM: To display the calendar
PROGRAM:
import calendar
yy = int(input("Enter year :"))
mm = int(input("Enter month :"))
print(calendar.month(yy, mm))
OUTPUT:
PROGRAM 10
AIM: To display number in Binary, Octal, Hexadecimal
PROGRAM:
n = int(input("Number :"))
print("Binary:",bin(n))
print("Octal:",oct(n))
print("Hexadecimal:",hex(n))
OUTPUT:
PROGRAM 11
AIM: To tell the Fibbonacci sequence
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:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
OUTPUT:
PROGRAM 12
AIM: To check for Armstrong Numbers
PROGRAM:
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
OUTPUT:
PROGRAM 13
AIM: To display pyramid
PROGRAM:
rows = int(input("Enter number of rows: "))
for i in range(rows):
for j in range(i+1):
print("* ", end="")
print("\n")
OUTPUT:
PROGRAM 14
AIM: To compute the power of a number
PROGRAM:
n = int(input("Number :"))
m = int(input("Power :"))
print(n ** m)
OUTPUT:
PROGRAM 15
AIM: To reverse a number
PROGRAM:
num = int(input("Number :"))
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reversed Number: " + str(reversed_num))
OUTPUT: