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

Ractical I and O

Uploaded by

thehackerguy99
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)
19 views

Ractical I and O

Uploaded by

thehackerguy99
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/ 13

CLASS – X (ARTIFICIAL INTELLIGENCE – 417)

PRACTICAL LIST – TOTAL MARKS 20


Python Program 1: Input two numbers from the user and display the sum and product
of these numbers.
INPUT
print(“Enter the first number”)
A=int(input())
print(“Enter the second number”)
B=int(input())
C=A + B
D=A * B
print(“The sum of these numbers is:”, C)
print(“The product of these numbers is:”, D)
OUTPUT
Enter the first number
32
Enter the second number
5
The sum of these numbers is: 37
The product of these numbers is: 160
Python Program 2: Input two numbers and print their quotient and remainder.
INPUT
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
Q=a//b
R=a%b
print("Quotient is:",Q)
print("Remainder is:",R)
OUTPUT
Enter the first number: 37
Enter the second number: 4
Quotient is: 9
Remainder is: 1
Python Program 3: Create a Python Program to modify a global value inside a function.
INPUT
x = 15
def change():
# using a global keyword
global x
# increment value of a by 5
x=x+5
print("Value of x inside a function :", x)
change()
print("Value of x outside a function :", x)
OUTPUT
Value of x inside a function : 20
Value of x outside a function : 20
Python Program 4: Input two numbers from the user and swap them. Pg.106
INPUT
# To take inputs from the user
x = input('Enter value of x: ')
y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x=y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
OUTPUT
Enter value of x: 5
Enter value of y: 10
The value of x after swapping: 10
The value of y after swapping: 5
Python Program 5: Input a number and check whether it is positive, negative or
neutral.
INPUT
num = int(input("Enter a number: "))
if num > 0:

print(num,"is a positive number")


if num < 0:
print(num,"is a negative number")
else:
print(num,"is a natural number")
OUTPUT
Enter a number: -1
-1 is a negative number
Python Program 6: Input five natural numbers and add them starting from 1.
INPUT
num = int(input("Enter a number: "))
i=0
sum=0
while i< num:
i=i+1
sum=sum+i
print(sum)
OUTPUT
Enter a number: 5
15
Python Program 7: Input five integer numbers and display their squares.
INPUT
numbers=[1,2,4,6,11]
sq=0
for val in numbers:
sq=val*val
print(sq)
OUTPUT
1
4
16
36
121
Python Program 8: Input a number and display if it is prime or not.
INPUT
num = 407
# To take input from the user
#num = int(input("Enter a number: "))
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
OUTPUT
407 is not a prime number
11 times 37 is 407
Python Program 9: Input three numbers and solve a quadratic equation.
INPUT
# Solve the quadratic equation ax**2 + bx + c = 0
# import math module
import math
a=1
b=5
c=6
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-math.sqrt(d))/(2*a)
sol2 = (-b+math.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))
OUTPUT
The solution are -3.0 and -2.0
Python Program 10: Input two numbers and find their LCM.
INPUT
def compute_lcm(x, y):
# choose the greater number
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = 54
num2 = 24
print("The L.C.M. is", compute_lcm(num1, num2))
OUTPUT
The L.C.M. is 216
Python Program in Jupyter Notebook 11: Python program to count the number of
digits in a number.
INPUT
n=int(input("Enter number:"))
count=0
while(n>0):
count=count+1
n=n//10
print("The number of digits in the number are:",count)
OUTPUT
Enter number:3689
The number of digits in the number are: 4

Python Program in Jupyter Notebook 12: Python program to find the sum of digits in a
number.
INPUT
n=int(input("Enter a number:"))
tot=0
while(n>0):
dig=n%10
tot=tot+dig
n=n//10
print("The total sum of digits is :",tot)
OUTPUT
Enter a number:5555
The total sum of digits is : 20

Python Program in Jupyter Notebook 13: Python program to reverse a given number.
INPUT
n=int(input("Enter a number:"))
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
print("The total sum of digits is :",rev)
OUTPUT
Enter a number:1234567
The total sum of digits is : 7654321

Python Program in Jupyter Notebook 14: Python program to check vowel or


consonant.
INPUT
ch=input("Enter a character: ")
if(ch=='A' or ch=='a' or ch=='E' or ch=='e' or ch=='I' or ch=='i' or ch=='O' or ch=='o' or
ch=='U' or ch=='u'):
print(ch,"is a Vowel")
else:
print(ch,"is a Consonant")
OUPUT
Enter a character: o
o is a Vowel
Python Program in Jupyter Notebook 15: Python program in Jupyter Notebook to find
the statistical function Mean, Median, Mode, Standard Deviation and Variance.
INPUT
import statistics
datasets=[5,9,7,4,2,6,8]

print("Mean is:",(statistics.mean(datasets)))
print("Median of data-set is:",(statistics.median(datasets)))
print("Mode of data-set is:",(statistics.mode(datasets)))
print("Standard Deviation of data-set is:",(statistics.stdev(datasets)))
print("Calculated variance of data-set is:",(statistics.variance(datasets)))
OUTPUT
Mean is: 5.857142857142857
Median of data-set is: 6
Mode of data-set is: 5
Standard Deviation of data-set is: 2.410295378065479
Calculated variance of data-set is: 5.809523809523809

Python Program in Jupyter Notebook 16: Draw a Line Graph in Python using
Matplotlib.
INPUT
# importing matplotlib module
from matplotlib import pyplot as plt
# x-axis values
x = [5,2,9,4,7]
# y-axis values
y = [10,5,8,4,2]
# Function to plot
plt.plot(x,y)
# Function to show the plot
plt.show()
OUTPUT

Python Program in Jupyter Notebook 17: Draw a Bar Graph in Python using
Matplotlib.
INPUT
# importing matplotlib module
from matplotlib import pyplot as plt
players=['Virat','Rohit','Shikhar','Hardik']
runs=[91,47,75,31]
plt.bar(players,runs,color='orange')
plt.title('Score Card')
plt.xlabel('Players')
plt.ylabel('Runs')
plt.show()

OUTPUT
Python Program in Jupyter Notebook 18: Draw a Pie Chart in Python using Matplotlib.

Python Program in Jupyter Notebook 19

Python Program in Jupyter Notebook 20


Open CV Practical 21:
Using the library : import cv2, matplotlib
Upload an image on the screen and give a proper title to it.

Open CV Practical 22:


Using the library : import cv2, matplotlib
Upload an image on the screen and display the picture in RGB color mode.
Open CV Practical 23:
Using the library : import cv2, matplotlib
Upload an image on the screen and display the image in grayscale mode.

NLP Program 24:


Using the Library: NLTK package
Using stemming with the NLTK Python framework.
NLP Program 25:
Using the Library: NLTK package
Using lemmatization with the NLTK Python framework.

You might also like