0% found this document useful (0 votes)
91 views15 pages

Chettinad Vidyashram STD X - Record Programs - 2021 - 2022 Artificial Intelligence

This document provides instructions for students to complete Python programs and record them in an index. It includes an index listing 10 Python programs and their titles and dates. The programs cover topics like calculating employee bonus, Fibonacci series, nested loops, list operations, searching tuples, dictionaries, roots of quadratic equations, multiplication tables, and using matplotlib for graphing. Students are instructed to write the code, input, and output for each program neatly in their record with the date and title.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views15 pages

Chettinad Vidyashram STD X - Record Programs - 2021 - 2022 Artificial Intelligence

This document provides instructions for students to complete Python programs and record them in an index. It includes an index listing 10 Python programs and their titles and dates. The programs cover topics like calculating employee bonus, Fibonacci series, nested loops, list operations, searching tuples, dictionaries, roots of quadratic equations, multiplication tables, and using matplotlib for graphing. Students are instructed to write the code, input, and output for each program neatly in their record with the date and title.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

CHETTINAD VIDYASHRAM

STD X – RECORD PROGRAMS – 2021 - 2022


ARTIFICIAL INTELLIGENCE (417)

INSTRUCTIONS TO WRITE IN RECORD:

1. Bonafide page – Write your name, class and section in block letters in the appropriate spaces
provided.
2. Fill the index neatly with the sno, title, and date given below. Page numbers according to the numbers
you start the new exercise. Write only the starting page of each exercise.
3. After the index, leave one page and start writing in the next page.
3. No scratches or overwriting.
4. Every exercise MUST start on a fresh page ONLY.
5. Write the date, title, question, coding in the ruled side with blue pen. Leave a line between the title,
question and coding.
6. In the unruled side cut and stick the output for each exercise. For this you have to take a printout of
the record programs.
7. Completed records will be checked and marked for internals.

INDEX:
PYTHON PROGRAMS
SNO DATE TITLE
1 7/6/21 TO CALCULATE THE BONUS OF AN EMPLOYEE
2 7/6/21 TO PRINT THE FIBONACCI SERIES USING while LOOP
3 14/6/21 TO PRINT THE FORMAT USING NESTED for LOOP
4 28/6/21 TO PERFORM OPERATIONS IN A LIST
5 28/6/21 TO SEARCH A STRING VALUE IN A TUPLE
6 5/7/21 TO CHANGE A VALUE IN A DICTIONARY USING THE KEY
7 5/7/21 TO PRINT THE ROOTS OF A QUADRATIC EQUATION
8 12/7/21 TO PRINT THE MULTIPLICATION TABLE
9 26/7/21 TO PRINT THE AREA AND CIRCUMFERENCE OF THE CIRCLE USING A
VARIABLE WITH THE CONSTANT VALUE

PYTHON PROGRAMS FOR AI

10 2/8/21 PYTHON GRAPH USING MATPLOTLIB


11 9/8/21 DATA ANALYSIS USING STATISTICS
12 16/8/21 IMAGE HANDLING USING OPENCV
Program 1. TO CALCULATE THE BONUS OF AN EMPLOYEE

Accept name, grade and salary of an employee. Calculate the bonus as per the criteria given below and
print all the details.
Bonus calculation:
Salary Bonus
Grade A: <10000 18% of the salary
10000 – 20000 20% of the salary
>20000 22% of the salary

Grade B: <10000 24% of the salary


10000 – 20000 26% of the salary
>20000 28% of the salary
To print the details in the following format:
NAME :
GRADE:
SALARY:
BONUS:
TOTAL SALARY:

PROGRAM 1:
nam = input("ENTER EMPLOYEE NAME : ")
sal = float (input("ENTER THE SALARY : "))
grade = input("ENTER THE GRADE A/B : ")
if grade=='A':
if sal<10000:
b=sal*0.18
elif sal>=10000 and sal<=20000:
b=sal*0.20
else:
b=sal*0.22
elif grade=='B':
if sal<10000:
b=sal*0.24
elif sal>=10000 and sal<=20000:
b=sal*0.26
else:
b=sal*0.28
print("NAME : ", nam)
print("GRADE : ", grade)
print("SALARY : ", sal)
print("BONUS : ", b)
print("TOTAL SALARY :", sal+b)

OUTPUT 1:

ENTER EMPLOYEE NAME : RIA


ENTER THE SALARY : 20000
ENTER THE GRADE A/B : A
NAME : RIA
GRADE : A
SALARY : 20000.0
BONUS : 4000.0
TOTAL SALARY : 24000.0

ENTER EMPLOYEE NAME : PUNITH


ENTER THE SALARY : 35000
ENTER THE GRADE A/B : B
NAME : PUNITH
GRADE : B
SALARY : 35000.0
BONUS : 9800.000000000002
TOTAL SALARY : 44800.0
Program 2. TO PRINT THE FIBONACCI SERIES USING while LOOP

Accept the number of terms and print the Fibonacci Series using while loop.

PROGRAM 2:
n=int(input("ENTER THE NUMBER OF TERMS : "))
i=3
a=0
b=1
print("FIBONACCI SERIES UPTO ", n, " TERMS : ")
print(a,end='\t')
print(b,end='\t')
while (i<=n):
c=a+b
print(c,end='\t')
a=b
b=c
i+=1

OUTPUT 2:

ENTER THE NUMBER OF TERMS : 10


FIBONACCI SERIES UPTO 10 TERMS :
0 1 1 2 3 5 8 13 21 34
Program 3. TO PRINT THE FORMAT USING NESTED for LOOP

To print the following format using nested for loop.


1
23
456
7 8 9 10

PROGRAM 3:
n=int(input("ENTER THE NUMBER OF ROWS : "))
c=1
print("FORMAT : ")
for i in range(1,n+1):
for j in range(1,i+1):
print(c,end=' ')
c+=1
print()

OUTPUT 3:

ENTER THE NUMBER OF ROWS : 4


FORMAT :
1
23
456
7 8 9 10
Program 4. TO PERFORM OPERATIONS IN A LIST

Write a program to perform the following tasks in a list.


a. Accept n integer elements in a list
b. Print the list
c. Arrange the elements in the ascending order using sort() function
d. Accept a number and print how many times it is present in the list using count() function
e. Accept a number and print the position of the number in the list using index() function.

PROGRAM 4:

n=int(input("ENTER THE LIMIT :"))


L=[]
print("ENTER ", n, " ELEMENTS IN THE LIST : ")
for i in range (1,n+1):
L.append(int(input("ENTER THE ELEMENT : ")))
print("GIVEN LIST : ", L)
L.sort()
print("ASCENDING ORDER OF THE ELEMENTS = ", L)
a=int(input("ENTER THE ELEMENT - CHECK NO. OF TIMES IT IS PRESENT"))
print("ELEMENT ",a," PRESENT ", L.count(a), " TIMES IN THE LIST")
b=int(input("ENTER THE ELEMENT - CHECK THE POSITION "))
print("ELEMENT", b, " PRESENT IN POSITION = ", L.index(b)+1)
OUTPUT 4:

ENTER THE LIMIT :10


ENTER 10 ELEMENTS IN THE LIST :
ENTER THE ELEMENT : 5
ENTER THE ELEMENT : 12
ENTER THE ELEMENT : 15
ENTER THE ELEMENT : 35
ENTER THE ELEMENT : 12
ENTER THE ELEMENT : 25
ENTER THE ELEMENT : 40
ENTER THE ELEMENT : 12
ENTER THE ELEMENT : 67
ENTER THE ELEMENT : 35
GIVEN LIST : [5, 12, 15, 35, 12, 25, 40, 12, 67, 35]
ASCENDING ORDER OF THE ELEMENTS = [5, 12, 12, 12, 15, 25, 35, 35, 40, 67]
ENTER THE ELEMENT - CHECK NO. OF TIMES IT IS PRESENT12
ELEMENT 12 PRESENT 3 TIMES IN THE LIST
ENTER THE ELEMENT - CHECK THE POSITION 25
ELEMENT 25 PRESENT IN POSITION = 6
Program 5. TO SEARCH A STRING VALUE IN A TUPLE

Assign a tuple with different elements. Accept a string value and print if it is present inside the tuple or
not.

PROGRAM 5:
t=(100, 'A', 'KAVIN', 105,'B','POOJA', 107, 'A', 'VINODH')
print("GIVEN TUPLE T= ", t)
c=0
nam=input("ENTER THE NAME FOR SEARCHING : ")
if nam in t:
print (nam, "IS PRESENT IN THE TUPLE")
else:
print (nam, "IS NOT PRESENT IN THE TUPLE")

OUTPUT 5:
===================
GIVEN TUPLE T= (100, 'A', 'KAVIN', 105, 'B', 'POOJA', 107, 'A', 'VINODH')
ENTER THE NAME FOR SEARCHING : POOJA
POOJA IS PRESENT IN THE TUPLE

GIVEN TUPLE T= (100, 'A', 'KAVIN', 105, 'B', 'POOJA', 107, 'A', 'VINODH')
ENTER THE NAME FOR SEARCHING : arun
arun IS NOT PRESENT IN THE TUPLE
Program 6. TO CHANGE A VALUE IN A DICTIONARY USING THE KEY

Assign a dictionary with the numbers from 1 – 7 as key and the names of the 7 wonders as the values.
Print the dictionary. Now change the value of key 2 from Hanging Gardens of Babylon to Redeemer
statue

PROGRAM 6:

d={1:'Great wall of China', 2: 'Hanging Gardens of Babylon', 3: 'Machu Picchu',


4: 'Chichen Itza', 5: 'Roman Colosseum', 6: 'Taj Mahal', 7: 'Petra'}
print("7 WONDERS OF THE ANCIENT WORLD : \n", d)
print()
d[2]= 'Redeemer statue'
print("7 WONDERS OF THE MODERN WORLD : \n", d)

OUTPUT 6:

7 WONDERS OF THE ANCIENT WORLD:


{1: 'Great wall of China', 2: 'Hanging Gardens of Babylon', 3: 'Machu Picchu', 4: 'Chichen Itza', 5:
'Roman Colosseum', 6: 'Taj Mahal', 7: 'Petra'}

7 WONDERS OF THE MODERN WORLD:


{1: 'Great wall of China', 2: 'Redeemer statue', 3: 'Machu Picchu', 4: 'Chichen Itza', 5: 'Roman
Colosseum', 6: 'Taj Mahal', 7: 'Petra'}
Program 7. TO PRINT THE ROOTS OF A QUADRATIC EQUATION
Accept the values of a, b, c and print the roots of the quadratic equation ax2 + bx + c.

PROGRAM 7:
import math
a=int(input("enter a:"))
b=int(input("enter b:"))
c=int(input("enter c:"))
d=(b*b)-(4*a*c)
if d==0:
print("Roots are real & equal\n")
print("r1 =", -b/(2*a))
elif d>0:
print("Roots are real & unequal\n")
print("r1=",(-b+math.sqrt(d))/(2*a))
print("r2=",(-b-math.sqrt(d))/(2*a))
else:
print("Roots are imaginary")

OUTPUT 7:
enter a:1
enter b:2
enter c:1
Roots are real & equal

r1 = -1.0

enter a:1
enter b:5
enter c:4
Roots are real & unequal

r1= -1.0
r2= -4.0

enter a:8
enter b:1
enter c:1
Roots are imaginary
Program 8. TO PRINT THE MULTIPLICATION TABLE

Accept the table and the limit and print the multiplication table.

PROGRAM 8:

t=int(input("ENTER THE TABLE : "))


L=int(input("ENTER THE LIMIT : "))
print("MULTIPLICATION TABLE OF ", t, " UPTO ", L)
for i in range (1,L+1):
print (t,'*',i,'=',t*i)

OUTPUT 8:

ENTER THE TABLE : 5


ENTER THE LIMIT : 10
MULTIPLICATION TABLE OF 5 UPTO 10
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Program 9. TO PRINT THE AREA AND CIRCUMFERENCE OF THE CIRCLE USING A
VARIABLE WITH THE CONSTANT VALUE

Accept the radius and print area and circumference of the circle using a variable PI which has the
constant value 3.14.

PROGRAM 9:

const.py
PI=3.14

REC1.py
#INVOKING CONSTANT VALUE FROM ANOTHER FILE
import const #Importing the PI value from the file const.py
r=float(input("ENTER THE RADIUS : "))
print("VALUE OF PI = ", const.PI)
print("AREA OF THE CIRCLE = ", const.PI * r *r)
print("CIRCUMFERENCE OF THE CIRCLE=", round(2*const.PI*r),2)

OUTPUT 9:
ENTER THE RADIUS : 5
VALUE OF PI = 3.14
AREA OF THE CIRCLE = 78.5
CIRCUMFERENCE OF THE CIRCLE= 31. 2
PYTHON PROGRAMS FOR AI

Program 10 : PYTHON GRAPH USING MATPLOTLIB


Program to print a graph using the package matplotlib

Installing matplotlib library

Desktop Taskbar  search box (near Start button) type cmd  select command prompt type pip
install matplotlib  press Enter key.

#Program Code 10
#PLOTTING GRAPHS USING matplotlib
from matplotlib import pyplot as plt

x=[5,2,9,4,7]
y=[10,5,8,4,2]
plt.plot(x,y,color="brown")
plt.ylabel("Y AXIS")
plt.xlabel("X AXIS")
plt.title("LINE GRAPH")
plt.show()

Output 10:
Program 11 : DATA ANALYSIS USING STATISTICS

Program to calculate and print mean, median and mode using the package statistics

# Program Code 11
# Printing mean, median and mode using statistics
# MEAN
import statistics
datasets=[5,9,7,4,2,6,8]
x=statistics.mean(datasets)
print("mean = ",round(x,2),"\n")

#MEDIAN
datasets=[4,-5,8,6,9,4,7,-2]
x=statistics.median(datasets)
print("median = ",round(x,2),"\n")

#MODE
set1 =[1, 2, 3, 3, 4, 4, 4, 5, 5, 6]
x=statistics.mode(set1)
print("mode = ",round(x,2),"\n")

Output 11:

mean = 5.86

median = 5.0

mode = 4
Program 12 : IMAGE HANDLING USING OPENCV

Program to manipulate and display images using OpenCV package

Installing opencv library


Desktop Taskbar  search box (near Start button) type cmd  select command prompt  Type pip
install opencv-contrib-python  press Enter key.

# Program Code 12
# Program using OpenCV to manipulate and display images
import cv2
im=cv2.imread("minion.jpg")
im=cv2.resize(im,(500,400))
cv2.imshow("INPUT IMAGE",im)
cv2.waitKey(0)

cv2.destroyAllWindows()

Output 12:

You might also like