[go: up one dir, main page]

0% found this document useful (0 votes)
10 views6 pages

Practical File Class X

Uploaded by

preetamvk829
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)
10 views6 pages

Practical File Class X

Uploaded by

preetamvk829
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/ 6

NAME:

ARTIFICIAL INTELLIGENCE

CLASS X- SEC:

[Author name]
[Date]
1. #WAP to check if a number is odd or even

n=int(input("enter value of n: "))


if n%2 == 0:
print("number is a even number")
else:
print("number is a odd number")
2. WAP to check is a given number is prime number or not

num=int(input("enter a number: "))


if num > 1:
for i in range(2,num//2):
if num % i==0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, " is not a prime number")

3. # WAP to check if a given yaer is leap year or not

year = int(input("Enter year : "))


if year % 4==0 and year % 100 != 0 or year % 400 == 0:
print("Leap year")
else:
print("Not a leap year")

4. #WAP to add natural numbers upto N (while loop)

n=int(input("enter value of n: "))


sum=0
i=1
while i<=n:
sum = sum+i
i+=1
print("sum of series upto n = ", sum)
5. #WAP to add natural numbers upto N (for loop)

n=int(input("enter value of n: "))


sum=0
for i in range(1,n+1):
sum = sum+i

print("sum of series upto n = ", sum)


6. #WAP to check whether an entered number is a palindropme or
not

num=int(input("enter value of number: "))


digit =0
while num>0:
r=num%10
digit = (digit*10)+r
num//=10
print(digit)
if num==digit:
print("number is palindrome")
else:
print("number is not palindrome")
7. WAP to find the Factorial of a number

num = int(input("Enter a number: "))

factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

8. WAP to print the fibonacci series till the number of terms entered
by the use using for loop

n=int(input("Please enter no of terms to be printed : "))


First, Second=0, 1
for i in range(0,n):
print(First,end=" ")
First,Second=Second,First+Second
9. WAP to create an array

import numpy as np
a=np.array([1,2,3])
b=np.array([10,20,30])
print(a,b)
c=a+b
print(c)
print(b**a)
10. # Write a Python program to calculate mean,median and
mode of an array.

import numpy as np
import statistics
a=np.array([14,15,16,16,19,19,19,22])
print(a)
m=statistics.mean(a)
med=statistics.median(a)
md=statistics.mode(a)
st=statistics.stdev(a)
var=statistics.variance(a)
print("Median:",med)
print("Mean:",m)
print("Mode:",md)
11. # Write a python program to display line chart based on
date and temperature by adding labels on X and Y

import matplotlib.pyplot as plt


date=['25/12','26/12','27/12','28/12']
temp=[18.5,12,17,11]
plt.plot(date,temp)
plt.xlabel('Date')
plt.ylabel('Temp')
plt.show()
12. # Write a python program to display bar chart based on
date and temperature by adding labels on X and Y

import matplotlib.pyplot as plt


date=['25/12','26/12','27/12','28/12']
temp=[18.5,12,17,11]
plt.bar(date,temp)
plt.xlabel('Date')
plt.ylabel('Temp')
plt.show()
13. # Write a python program to display bar chart horizontally
based on date and temperature by adding labels on X and Y

import matplotlib.pyplot as plt


date=['25/12','26/12','27/12','28/12']
temp=[18.5,12,17,11]
plt.barh(date,temp)
plt.xlabel('Date')
plt.ylabel('Temp')
plt.show()
14. # Write a python program to display line chart based on
date and temperature by adding labels on X and Y

import matplotlib.pyplot as plt


date=['25/12','26/12','27/12','28/12']
temp=[18.5,12,17,11]
plt.scatter(date,temp,c='red')
plt.title('Sactter Plot')
plt.xlabel('Date')
plt.ylabel('Temp')
plt.show()
15. #Write a Python program to display an image

import cv2
import matplotlib.pyplot as plt
img=cv2.imread("CV.jpg")
plt.imshow(img)
plt.title("COMPUTER VISION")
plt.show()
16. # Write the Python code to display an image in grey scale.

import cv2
import matplotlib.pyplot as plt
img=cv2.imread("CV.jpg",0)
plt.imshow(img,cmap='gray')
plt.title("COMPUTER VISION(gray)")
plt.show()
17. #Write the Python code to find the size, minimum and
maximum pixel value of an image.

import cv2
import matplotlib.pyplot as plt
img=cv2.imread("CV.jpg")
print(img.shape)
print(img.min())
print(img.max())
plt.imshow(img)
plt.show()
18. #Write the Python code to resize an image.

import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread("CV.jpg")
print("image1 shape=",img.shape)
img2=cv2.resize(img,(500,500))
print("image2 shape=",img2.shape)
plt.imshow(cv2.cvtColor(img2,cv2.COLOR_BGR2RGB))
plt.show()

19. List Slicing

L=['E','D','U','C','A','T','I','O','N']
#The output would remain the same for the below mentioned
print(L[:])
Output: ['E','D','U','C','A','T','I','O','N']
print(L[::])
Output: ['E','D','U','C','A','T','I','O','N']
print(L[0:])
Output: ['E','D','U','C','A','T','I','O','N']
print([-9:])
Output: ['E','D','U','C','A','T','I','O','N']
#The output would remain the same for the below mentioned
print(L[0:3])
Output:[‘E’,’D’,’U’]
print(L[:3])
Output:[‘E’,’D’,’U’]
print(L[-9:-6])
Output:[‘E’,’D’,’U’]
print(L[:-6])
Output:[‘E’,’D’,’U’]
#The output would remain the same for the below mentioned
print(L[3:6])
Output:[‘C’,’A’,’T’]
print(L[-6:-3])
Output:[‘C’,’A’,’T’]
print(L[3:-3])
Output:[‘C’,’A’,’T’]
#The output would remain the same for the below mentioned
print(L[7:4:-1])
Output:[‘O’,’I’,’T’]
print(L[-2:-5:-1])
Output:[‘O’,’I’,’T’]
print(L[7:-5:-1])
Output:[‘O’,’I’,’T’]
print(L[-2:4:-1])
Output:[‘O’,’I’,’T’]
#Reverse of list
print(L[::-1])
Output:[‘N’,’O’,’I’,’T’,’A’,’C’,’U’,’D’,’E’]

You might also like