You are on page 1of 20

Kanha Makhan Public School

ARTIFICIAL INTELLIGENCE (417)

REPORT FILE

PREPARED BY: SHRADDHEY SHARMA


CLASS: 10th – H
CBSE Board Roll No……………………….
Session: 2023-24

SUBMITTED TO: Mr. Ritik Agrawal


CERTFICATE

This is to certify that this report file is the bonafide

work of Master Shraddhey Sharma of Class

10th-H, Class Roll no.-36 in the session 2023-24 of

KANHA MAKHAN PUBLIC SCHOOL,

MATHURA carried out in the school under my

supervision.

Teacher’s Signature
ACKNOWLEDGEMENT

I am thankful to my Artificial intelligence teacher for

guidance and support. I also thank my Principal

Mr. Anil Yaduvanshi. I would also like to thank my

parents and my classmates for encouraging me during

this report file. Finally, I would like to thank

CBSE for giving methis opportunity to undertake

this practical work.

Shraddhey
Sharma Class-
10th-H
CBSE Board Roll No._
PYTHON
PROGRAM

PROBLEM: 1
Write a program to check whether the entered number is
palindrome or not (Hint: Palindrome is a number that reads the
same forward and backward e.g.121).

CODE:
a=int(input("Enteranumber:"));b=a;c=0 while(a>0): d=a
%10
c=c*10+d
a=a//10
if(b==c):
print("Thenumberispalindrome!")
else:
print("Notapalindrome!")
OUTPUT:
PROBLEM: 2
Write a program to print the following pattern:
*****
****
***
**
*
CODE:
rows=int(input("EnterNumberofRows="))
for i in range(rows + 1, 0, -1):
forjinrange(0,i-1): print("*",
end='')
print("")
OUTPUT:
PROBLEM:3
Write a program to enter a number and display its
factorial.
CODE:
a=int(input("Enteranumber:")) factorial
=1
ifa<0:
print("Factorialdoesnotexistfornegative
numbers") elifa==0:
print("Thefactorialof0is1")
else:
for i in range(1,a + 1):
factorial=factorial*i
print("Thefactorialof",a,"is",factorial)
OUTPUT:
PROGRAM:4
Write a program to enter the runs scored by a batsman in five
innings and calculate strike rate in each match, also present the
highest strike rate. (Hint: Strike rate= Runs scored by player/Total
balls faced *100).
CODE:
a=int(input("ENTER NUMBER OF RUNS IN 1ST
INNING="));b=int(input("ENTE NUMBER OF RUNS IN 2N
R D
INNING="));c=int(input("ENTE NUMBER OF RUNS IN 3RD
R
INNING="));d=int(input("ENTERNUMBEROFRUNSIN4THINNING="))
e=int(input("ENTERNUMBER OF RUNS IN
5ST INNING="));k=int(input('ENTER
NUMBER OF RUNS IN ONE INNING='))
f=a/k*100;g=b/k*100.;h=c/k*100;i=d/k*100;j=e/k*100
print('The strike rate in first inning is',f);print('The strike rate in Second
inning is',g);print('The strike rate in Third inning is',h);print('The strike
rate in Fourth inning is',i)
print('The strike rate in fifth inning is',j);print('The Highest strike Rate
is',(max(f,i,g,j,h)))
OUTPUT:
PROGRAM:5
Write a program to calculate area of circle, triangle and
rectangle depending on user’s choice. The choice should be
entered by the user in the form of a menu. Wrong choice should
be addressed.
CODE:
a=str(input('EnterYourChoice(circle,triangleorrectangle)=')) if
(a=='circle'):
b=float(input('Enterradiusofcircle='))
print('Area of circle is ',(22/7)*b*b)
if (a=='rectangle'):
c=float(input('Enter Length='))
d=float(input('Enter Breadth='))
print("Areaofrectangleis",c*d)
if (a=='triangle'):
e=float(input('Enter Height='))
f=float(input('Enter Base='))
print("AreaofTriangleis",0.5*e*f)

OUTPUT:
PROGRAM:6
Write a program using for loop, to input a number and print its
mathematical table upto 10 terms in the following format:
3*1=3
3*2=6

CODE:
a=int(input('EnterNumber='))
for i in range(1,11):
print(a,'*',i,'=',a*i)
OUTPUT:
PROBLEM:7
Write a program to obtain temperature in Celsius and convert it into
Fahrenheit using the given formula.
{Hint:F=C*9/5+32}
CODE:
a=float(input('EntertempratureinCelsius='))
b=(a*(9/5))+32
print('THETEMPRATUREINFAHRENHEITIS',b)
OUTPUT:
PROBLEM: 8
Write a program to find the largest number among the three
numbers, numbers should be entered by the user.
CODE:
a=float(input('Enter First Number='))
b=float(input('Enter Second Number='))
c=float(input('Enter Third Number='))
print('TheLargestnumberis',max(a,c,b))
OUTPUT:
PROBLEM:9
Write a program to enter time in minutes and convert it into
hours and minutes.
CODE:
a=int(input("EnterTimeinMinutes="))
b=a//60
c=a%60
print('TheTimeis',b,'Hoursand',c,'Minutes')
OUTPUT:
PROBLEM:10
Write a program to find the sum of all the digits of a number
input by the user.
CODE:
a=int(input('EnterNumber='))
b=0
foriinstr(a): b
+= int(i)
print('TheSumofDigitsofNumbersis', b)
OUTPUT:
PROBLEM:11
Write a program to enter a number and check whether it is a
prime number or not.
CODE:
a=int(input('EnterNumber='))
b=0
i=1
while (i<=a):
if(a%i==0):
b=b+1
i=i+1
if
(b==2):
print("TheNumberisPrime")
else:
print("TheNumberisnotprime")
OUTPUT:
PROBLEM:12
Write a program to create the following arrays: A= [1,3,5,7]
B=[2,4,6,8]
And perform the following operations on them–1.Addition 2.Multiplication

CODE:
importnumpy
A=numpy.array([1,3,5,7])
B=numpy.array([2,4,6,8])
addition_result = numpy.add(A, B)
print("AdditionResult:",addition_result)
multiplication_result = numpy.multiply(A, B)
print("Multiplication Result:",multiplication_result)
OUTPUT:
PROBLEM:13
Write a program to read an image and present it in gray scale format.

CODE:
importcv2
image = cv2.imread("1.jpg")
cv2.imshow('Original',image)
cv2.waitKey(0)
gray_image=cv2.cvtColor(image,
cv2.COLOR_BGR2GRAY)
cv2.imshow('Grayscale',gray_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
OUTPUT:
Problem:14
Document1: Amit and Amita are twins.
Document2: Amit lives with his grandparents in Shimla.
Document3: Amita lives with her parents in Delhi.

Create a step-by-step approach to implement a bag of words algorithm.


Step-by-StepApproach:

1. **Tokenization:**
- Split each document into individual words or tokens.
- For instance:
- Document1tokens:["Amit","and","Amita","are","twins"]

- Document2tokens:["Amit","lives","with","his","grandparents","in","Shimla"]

- Document3tokens:["Amita","lives","with","her","parents","in","Delhi"]

2. Createdictionary:
- Create a set of unique words from all the documents. This set will be your vocabulary.
- Vocabulary:{"Amit","and","Amita","are","twins","lives","with","his","grandparents","in","Shimla",
"her", "parents", "Delhi"}

3. **Vectorization:**
- Represent each document as a vector based on the vocabulary.
- Count the frequency of each word from the vocabulary in the respective documents and place these
counts in the vector at the corresponding index.
word Document1 Document2 Document3
amit 1 1 0
and 1 0 0
amita 1 0 1
Are 1 0 0
twins 1 0 0
Lives 0 1 1
With 0 1 1
His 0 1 0
grandparents 0 1 0
In 0 1 1
shimla 0 1 0
her 0 0 1
parents 0 0 1
delhi 0 0 1
PROBLEM:15
Consider the following confusion matrix and answer the questions:
Reality
Confusion Matrix True False
True 86 12
Prediction False 10 79

(i) CalculateRecall,Precision,F1Score.
(ii) How many in totals were predicted ‘Yes’and ‘No’?

SOLUTIONS:
(i) CalculateRecall,Precision,F1Score:
Recall = True Positives / (True Positives + False
Negatives)Recall=86/(86+10)≈0.8958
Precision = True Positives / (True Positives + False Positives)
Precision=86/(86+12)≈0.8776
F1Score=2*(Precision*Recall)/(Precision+Recall)
F1Score≈0.8866
(ii) TotalPredictionsfor'Yes'and'No':
TotalPredictionsfor'Yes'(TruePositives+FalseNegatives)=86
+10=96
TotalPredictionsfor'No'(FalsePositives+TrueNegatives)=12
+79=91
Intotal:
- Predicted'Yes':96
- Predicted'No':91

You might also like