0% found this document useful (0 votes)
33 views

AI Project

The document contains 14 programs written in Python demonstrating concepts of artificial intelligence and programming such as adding numbers, finding maximum/minimum, calculating factorials, compound interest, determining if a number is Armstrong, swapping list elements, solving quadratic equations, type conversion, random number generation, math functions, and absolute value calculation. The programs have corresponding outputs.

Uploaded by

srijang272
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

AI Project

The document contains 14 programs written in Python demonstrating concepts of artificial intelligence and programming such as adding numbers, finding maximum/minimum, calculating factorials, compound interest, determining if a number is Armstrong, swapping list elements, solving quadratic equations, type conversion, random number generation, math functions, and absolute value calculation. The programs have corresponding outputs.

Uploaded by

srijang272
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

OPG WORLD SCHOOL

CLASS IX

ARTIFICIAL INTELLIGENCE
PRACTICAL FILE

NAME:
SRIJAN
GHOSH

SECTION:
9th A
PROGRAM 1
Program :
# Python3 program to add two numbers
num1 = 15
num2 = 12

# Adding two nos


sum = num1 + num2

# printing values
print("Sum of", num1, "and", num2 , "is", sum)

Output:

PROGRAM 2
Program :
# Python program to find the
# maximum of two numbers

def maximum(a, b):

if a >= b:
return a
else:
return b

# Driver code
a=2
b=4
print(maximum(a, b))

Output:
PROGRAM 3
Program :
# Python 3 program to find
# factorial of given number
def factorial(n):

# single line to find factorial


return 1 if (n==1 or n==0) else n * factorial(n - 1)

# Driver Code
num = 5
print("Factorial of",num,"is",factorial(num))

Output:
PROGRAM 4
Program :
# Python3 program to find simple interest
# for given principal amount, time and
# rate of interest.

def simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)

si = (p * t * r)/100

print('The Simple Interest is', si)


return si

# Driver code
simple_interest(8, 6, 8)

Output:
PROGRAM 5
Program :
# Python3 program to find compound
# interest for given values.

def compound_interest(principal, rate, time):

# Calculates compound interest


Amount = principal * (pow((1 + rate / 100), time))
CI = Amount - principal
print("Compound interest is", CI)

# Driver Code
compound_interest(10000, 10.25, 5)

Output:
PROGRAM 6
Program :
# Python program to determine whether
# the number is Armstrong number or not

# Function to calculate x raised to


# the power y
def power(x, y):

if y == 0:
return 1
if y % 2 == 0:
return power(x, y // 2) * power(x, y // 2)

return x * power(x, y // 2) * power(x, y // 2)

# Function to calculate order of the number


def order(x):

# Variable to store of the number


n=0
while (x != 0):
n=n+1
x = x // 10

return n

# Function to check whether the given


# number is Armstrong number or not
def isArmstrong(x):

n = order(x)
temp = x
sum1 = 0

while (temp != 0):


r = temp % 10
sum1 = sum1 + power(r, n)
temp = temp // 10

# If condition satisfies
return (sum1 == x)

# Driver code
x = 153
print(isArmstrong(x))

x = 1253
print(isArmstrong(x))
Output:

PROGRAM 7
Program :
# Python3 program to swap first
# and last element of a list

# Swap function
def swapList(newList):
size = len(newList)

# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp

return newList

# Driver code
newList = [12, 35, 9, 56, 24]

print(swapList(newList))
Output:

PROGRAM 8
Program :
# Solve the quadratic equation ax**2 + bx + c = 0

# import complex math module


import cmath

a=1
b=5
c=6

# calculate the discriminant


d = (b**2) - (4*a*c)

# find two solutions


sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)

print('The solution are {0} and {1}'.format(sol1,sol2))


Output:

PROGRAM 9
Program :
# Square root calculation

import math
math.sqrt(4)

Output:
PROGRAM 10
Program :

num1 = 5

print(num1, 'is of type', type(num1))

num2 = 5.42

print(num2, 'is of type', type(num2))

num3 = 8+2j

print(num3, 'is of type', type(num3))

Output:
PROGRAM 11
Program :

num1 = int(2.3)

print(num1) # prints 2

num2 = int(-2.8)

print(num2) # prints -2

num3 = float(5)

print(num3) # prints 5.0

num4 = complex('3+5j')

print(num4) # prints (3 + 5j)

Output:
PROGRAM 12
Program :

import random

print(random.randrange(10, 20))

list1 = ['a', 'b', 'c', 'd', 'e']

# get random item from list1

print(random.choice(list1))

# Shuffle list1

random.shuffle(list1)

# Print the shuffled list1

print(list1)

# Print random element

print(random.random())
Output:

PROGRAM 13
Program :

import math

print(math.pi)

print(math.cos(math.pi))

print(math.exp(10))

print(math.log10(1000))
print(math.sinh(1))

print(math.factorial(6))

Output:

PROGRAM 14
Program :

import random

random.seed(2)

print(random.random())

print(random.random())

print(random.random())
Output:

PROGRAM 14
Program :

number = -20

absolute_number = abs(number)

print(absolute_number)

# Output: 20

Output:

You might also like