0% found this document useful (0 votes)
27 views26 pages

AI Assignments for Practical Record Class-X

Uploaded by

swoyamnayak26
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)
27 views26 pages

AI Assignments for Practical Record Class-X

Uploaded by

swoyamnayak26
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/ 26

ASSIGNMENT-1

ADVANCE PYTHON
1. Write a program in python to display your
name along with your age and school name in
separate lines.
Ans: name = input(“Enter your name:”)
age = int(input(“Enter your age:”))
school = input(“Enter your school name:”)
print (name, “\n”)
print (age, “\n”)
print (school)
2. Write a program in python to calculate the
total bill of house rent and electricity bill when the
user enters the electricity units consumed.
Ans: units= int(input(“Enter the electricity units
consumed:”))
price= int(input(“Enter the price of one unit of
electricity:”))
rent = 500
bill= rent + units*price
print (bill)
3. Write a program in python to find whether the
user is eligible for the job or not according to his
age
Ans: age = int(input(“Enter your age:”))
If age>=18:
print (“Eligible for the job”)
Else:
Print (“ Not eligible for the job”)
4. Write a program in python to print odd and
even series of number
Ans: Odd Series:
n= int(input(“Enter the numbers you want in the
series”))
a=1
for i in range (1,n+1,1):
print (a, end= ‘ ’)
a = a+2
Even Series:
n= int(input(“Enter the numbers you want in the
series”))
a=2
for i in range (1,n+1,1):
print (a, end= ‘ ’)
a = a+2
ASSIGNMENT-2
1.Write a program in python to print Fibonacci series
Ans: n= int(input(“Enter the numbers you want in the
series”))
a=0
b=1
print (a, b, end= ‘ ’)
For i in range (3, n+1, 1):
c= a + b
print (c, end= ‘ ’)
a=b
b=c
2.Write a program in python to make the following
pattern:
*
* *
* * *
* * * *
Ans: n= int(input(“Enter the number of lines you
want”))
for i in range (1, n+1, 1):
for j in range (1, n+1, 1):
print (“ * ”, end= ‘ ’)
print ( )
3.Write a program in python to make the following
pattern:
1
1 2
1 2 3
1 2 3 4
Ans: n= int(input(“Enter the number of lines you
want”))
for i in range (1, n+1, 1):
for j in range (1, n+1, 1):
print (“ j ”, end= ‘ ’)
print ( )
4.Write a program in python to find whether the
number entered by the user is palindrome or not
Ans: # palindrome number …..n = 3478
#output …. Reverse the number= 8743
n= input(“Enter the numbers in non-fraction form to
reverse”)
x=len(n)
rev=0
n=int(n)
m=n
if n>0:
for i in range (x):
r = n % 10
n = n // 10
rev = rev *10 + r
if (m==rev):
Print(“Answer is”, rev, “and”, m, “so number is
palindrome”)
else:
Print (“Answer is”, rev, “and”, m, “so number is
not palindrome”)
else
print (“Number must be positive”)
ASSIGNMENT-3
1.Write a program in python to print the following
pattern
4 4 4 4
3 3 3
2 2
1
Ans: n= int(input(“Enter the number of line you want
to print”))
a=n
for i in range (1, n+1):
for x in range (n, i-1, -1):
print (a, end= ‘ ’)
a = a-1
print ( “ ”)
2.Write a program in python to print the number of
vowels, consonant, digits and spaces in the text
entered by the user.
Ans. str=input(“Enter a string:”)
n=len(str)
x=0
v=0
c=0
s=0
d=0
while x<n:
if str[x]== ‘a’ or str[x]== ‘e’ or str[x]== ‘i’ or str[x]==
‘o’ or str[x]== ‘u’:
v=v+1
elif str[x]== ‘ ’:
s = s+1
elif str[x]== ‘0’ or str[x]== ‘1’ or str[x]== ‘2’ or
str[x]== ‘3’ or str[x]== ‘4’:
d= d+1
elif str[x]== ‘5’ or str[x]== ‘6’ or str[x]== ‘7’ or
str[x]== ‘8’ or str[x]== ‘9’:
d= d+1
else:
c = c+1
x = x+1
print (“vowels are”, v)
print (“Consonants are”, c)
print (“Spaces are”, s)
print (“Digits are”, d)
3.Write a program in python to make the following
pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4
1 2 3
1 2
1
Ans: n= int(input(“Enter the number of lines you want
to print”))
for i in range (1, n+1):
a=1
for x in range (n, i – 1, -1):
print (a, end= “ ”)
a= a+1
print (“ ”)
4.Write a program in python to make the following
pattern
1
1 2
1 2 3
1 2 3 4
Ans: n= int(input(“Enter the number of lines you want
to print”))
for i in range (1, n+1):
for c in range (n, i – 1, -1):
print (“ ”, end= “ ”)
for j in range (n, i+1):
print(j, end= “ ”)
print (“ ”)
ASSIGNMENT-4
DATA SCIENCE
1.Write a program in python to plot the data series:
Rol Name Clas M_Hind M_En M_Math M_EV
l s i g s S
No.
1 Ayan 4 56 67 62 59
2 Ayush 4 67 78 73 69
3 Suma 4 45 65 68 63
n
4 Juhi 4 69 78 75 72
5 Rohan 4 55 62 60 58
6 Raghu 4 66 73 71 70
7 Tarun 4 67 88 80 73
8 Zahir 4 78 83 73 72
9 Milan 4 79 73 68 68
10 Zubin 4 71 69 72 65
Create the above file and save is as student.csv

import pandas as pd
dataframe = pd.read_csv(“student.csv”)
print (dataframe.head())

o/p – It will display the output on the blank page


after execution of the code.
2.Write a program in python to plot a line graph with
the following data:
Month = [“JUNE”, “JULY”, “AUG”, “SEP”, “OCT”]
Rainfall (in mms) = [140, 160, 130, 110, 170]
Ans: plt.figure(figsize(5, 5))
Month = [“JUNE”, “JULY”, “AUG”, “SEP”, “OCT”]
Rainfall = [140, 160, 130, 110, 170]
plt.plot (Month, Rainfall)
plt.title (“My First Graph”)
plt.xlabel(“X_numbers”)
plt.ylabel(“y_numbers”)
plt.show( )
3.Write a program in python to plot 4 different
graphs in a single plot with the help of subplots. For
this let us first assume the data for 4 different
graphs:
Ans: # Here we are taking same value of x for all
graphs
Y1 = [0, 2, 4, 6]
Y2 = [11, 13, 15, 17]
Y3 = [12, 22, 32, 52]
Y4 = [34, 45, 56, 53]
X = [1, 2, 3, 4]
# Let’s first create subplot
Fig, ax = plt.subplots (2, 2)
ax [0, 0].plot(x, y1)
ax [0, 1].plot(x, y2)
ax [1, 0].plot(x, y3)
ax [1, 0].plot(x, y4)
plt.show ( )
ASSIGNMENT-5
COMPUTER VISION
1. Write a program in python to display an image in
RGB.
import cv2 #Import cv2 package from matplotlib
import pyplot as plt # Load the image file into
memory
img = cv2.imread (‘D:\ flower.jpg’) # put image file
path
plt.imshow (cv2.cvtcolor(img,
cv2.COLOR_BGR2RGB))
plt.title(‘flower’)# write the code to display the axis
in the image plotted i.e. plt.axis (‘off’)# Write the
code to plot the image i.e. plt.show()
2.Write a program in python and resize an image
Cropping an Image
# Extract a square that focuses on the flower’s size
# Remember, your current image size is 3967 x 2977
roi = img [1500:2500,1000:2000] #img[range of y,
range of x]
plt.imshow(cv2.cvtColor(roi,cv2.COLOR_BGR2RGB))
plt.title(‘flower’)
plt.axis(‘off’)
plt.show( )
Resizing an Image
img
=cv2.imread(‘C”/Users/user/Desktop/original_flowe
r.jpg’)
resized = cv2.resize(img,(200,200))
plt.imshow(cv2.cvtColor(resized,cv2.COLOR_BGR2R
GB))
plt.title(‘flower’)
plt.axis(‘on’)
plt.show( )
print(resized.shape)
ASSIGNMENT-6
NATURAL LANGUAGE PROCESSING
1.Write a program in python to show tokenization,
stemming and lemmatization for the corpus:
Tokenization
Import nltk
Sentence = “ “ “ Tokens is a term used for any
word or number or special character occurring in a
sentence.
Under tokenization, every word, number and special
character is considered separately and each of them
is now a separate token.”””
token = nltk.word_tokenize (sentence)
print (token)
Stemming
from nltk.stem import PorterStemmer
porter = PorterStemmer()
wl= [“like”, “dryness”, “dried”, “liking”, “drys”,
“likes”]
for w in wl:
print(porter.stem(w))

Lemmatization
from nltk.stem import WordNetLemmatizer
l= WordNetLemmatizer()
wl= [“like”, “dryness”, “dried”, “liking”, “drys”,
“likes”]
for w in wl:
print(l.lemmatize(w))

ASSIGNMENT-7
EVALUATION

1.Write a program in python to display how to


calculate recall, accuracy and precision using the
following actual and predicted data.
Data = {‘y_Actual’: [1,0,0,1,0,1,0,0,1,0,1,0],
Y_Predicted’: [1,1,0,1,0,1,1,0,1,0,0,0]
}
Ans: Based on the above data, the following
confusion matrix is created
The confusion Actual: 0 Actual: 1
matrix
Predicted: 0 5 2
Predicted :1 1 4

import pandas as pd
from pandas_ml import ConfusionMatrix
import matplotlib.pyplot as plt
data = {‘y_Actual’: [1,0,0,1,0,1,0,0,1,0,1,0],
‘Y_Predicted’: [1,1,0,1,0,1,1,0,1,0,0,0]
}
df = pd.DataFrame(data, columns = [‘y_Actual’,
‘Y_Predicted’])
Confusion matrix =
ConfusionMatrix(df[‘y_Actual’],df[‘y_Predicted’])
Confusion_Matrix.print_stats()
ASSIGNMENT-8
1.Write a program in Python to print String in output
Screen
Ans: print("Hello\n Sir")
print("I am", end = " ")
print("Student of")
print("KV No 4, BBSR")
O/P – Hello
Sir
I am student of
KV No4, BBSR
2. Write a program in Python to input name and age
and print it
Ans: #Program to Print Name and Age
nm = input("Enter your name : ")
age = input("Enter your age : ")
print("You are Mr. ", nm)
print("Your age is : ", age)
O/P - Enter your name : XYZ
Enter your age : 20
You are Mr. XYZ
Your age is :20
3. Write a program in Python to add two numbers
# Program to add two numbers
a = int(input("Enter First number : "))
b = int(input("Enter Second number : "))
c=a+b
print(a, " + ", b," = ", c)
O/P: Enter First number :10
Enter Second number :20
10+20 = 30
4. Write a program in Python to input 2 no.s and print
the addition and multiplication
#Program of Arithmetic Operator
a = int(input("Enter First number : "))
b = int(input("Enter Second number : "))
res1 = a + b
res2 = a * b
print(a," + ",b," = ", res1)
print(a," * ",b," = ", res2)
o/p: Enter First number : 9
Enter Second number : 6
9 + 6 = 15
9 * 6 = 54
ASSIGNMENT-9
1. Write a program in Python to input an integer and
print its square and cube
num = int(input("Enter any number :"))
sq = num*num
cu = num*num*num
print("Squre is ", sq)
print("Cube is ",cu)
o/p: Enter any number : 8
Square is 64
Cube is 512
2. Write a program in Python to input a number and print first 5
multiple of that number
#Program to print first 5 multiple
num1 = int(input("Enter any number : "))
m2 = num1*2
m3 = num1*3
m4 = num1*4
m5 = num1 *5
print("First five multiples are :")
print(num1, m2, m3, m4, m5)
o/p: Enter any number : 7
First five multiples are :
7 14 21 28 35
3. Write a program in Python to input Principal, Rate and time
and calculate Simple Interest.
#Program of Simple Interest
pr = int(input("Enter Principal : "))
rate = int(input("Enter Rate : "))
ti = int(input("Enter Time : "))
si = pr * rate * ti/100
print("Simple Interest is : ,si)
O/P: Enter Principal: 100
Enter Rate: 5
Enter Time: 3
Simple Interest is : 15.0
4. Write a program in Python to input two numbers and calculate
the Quotient and Remainder.
#Program of Quotient and Remainder
print("Program of Quotient and Remainder)
n1 = int(input("Enter First number : "))
n2 = int(input("Enter Second number : "))
R = n1 % n2
Q = n1 // n2
print("Quotient is : ",Q)
print("Remainder is : ",R)
O/P: Program of Quotient and Remainder
Enter First number: 22
Enter Second number:6
Quotient is : 3
Remainder is : 4
ASSIGNMENT-10
1. Write a program in Python to input the length and
breadth and calculate the area of the rectangle.
#Program to Calculate Rectangle
a =12
b=5
area = a * b
print("Length is : ",a)
print("Breadth is : ",b)
print("Area is : ", area)
O/P: Length is : 12
Breadth is : 5
Area is: 60
2. Write a program in Python to input your age and print
present age, age after 5 and 10 yrs.
# Program to print age after 5 yr and after 10 yr
age = int(input("Enter your present age : "))
age5 = age + 5
age10 = age + 10
print("Your present age is : ", age)
print("Your age after 5 years : ", age5)
print("Your age after 10 years : ", age10)
O/P: Enter your present age : 12
Your present age is : 12
Your age after 5 years : 17
Your age after 10 years : 22
3. Write a program in Python to input Cost Price and
Selling Price and Print Profit or Loss
#Program of Profit / Loss
print("Program - Profit or Loss")
cp = int(input("Enter Cost Price : "))
sp = int(input("Enter Selling Price : "))
if(cp>sp):
ans = cp - sp
print("Loss for Rs. ",ans)
elif(sp>cp):
ans = sp - cp
print("Profit for Rs. ",ans)
else:
print("No Profit No Loss")
O/P: Program – Profit or Loss
Enter Cost Price: 100
Enter Selling Price : 75
Loss for Rs. 25
Program – Profit or Loss
Enter Cost Price: 80
Enter Selling Price : 110
Profit for Rs. 30
4. Write a program in Python to input the marks of students and
find Pass or Fail
#Student pass or fail
mark = int(input("Enter Marks of Student : "))
if(mark >= 33):
print("Student Pass")
else :
print("Student Fail")
print("Over")
O/P: Enter Marks of Student : 65
Student Pass
Over
Enter Marks of Student : 21
Student Fail
Over
ASSIGNMENT-11
1. Write a program to input a number and find whether it is Zero,
Positive or negative
#Number to find whether Positive, Negative or Zero
num = int(input("Enter any Number : "))
if(num>=0):
if(num==0):
print("Number is ZERO")
else:
print("Positive number")
else:
print("Negative number")
O/P: Enter any Number :5
Positive number
Enter any Number :-5
Negative number
2. Write a program in Python to input a number and print its
absolute number.
#program Absolute
num = int(input("Enter any number: "))
if(num<0):
num = -1*num
print("Absolute number is :",num)
O/P: Enter any number: -9
Absolute number is : 9
Enter any number: 99
Absolute number is : 99
3. Write a program in Python to input Marks and print the grade
based on the marks

# Program to find grade


print("Program to Find grade of student ")
nm = input("Student name : ")
mrk = int(input("Enter student marks : "))
if(mrk>=90):
print("Grade of ",nm," is A")
elif(mrk>=60):
print("Grade of ",nm," is B")
elif(mrk>=33):
print("Grade of ",nm," is C")
else :
print("Grade of ",nm," is D")
O/P: Program to Find grade of student
Student name : Vimal
Enter student marks : 92
Grade of Vimal is A
Program to Find grade of student
Student name : Raj
Enter student marks : 52
Grade of Vimal is C
4. Write a program in Python to input Marks and print the grade
based on the marks

# Program of Table of any number


import time
t = int(input("Enter the number for table : "))
for x in range(1,11):
time.sleep(0.5)
print(t," * ",x," = ",t * x)
O/P: Enter the number for table :5
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

You might also like