PYTHON PROGRAM FOR CLASS 10
1. WRITE A RPOGRAM TO ADD TWO NUMBER.
x=int (input (“Enter the first number:”))
y= int (input (“Enter the first number:”))
z=x+y
print (“The addition of two number is:”,z)
2. WRITE A PROGRAM TO CALCULATE AREA AND PERIMETER OF
SQUARE.
side = int(input(“Enter side of a square:”)
area = side *side
perimeter= 4*side
print (“Area of a square:”,area)
print (“Perimeter of a square”, perimeter)
3. WRITE A PROGRAM TO CALCULATE THE PERCENTAGE OF
MARKS SCORED BY STUDENT IN 5 SUBJECT.
eng=float(input(“Enter the marks scored in english:”))
language2 = float(input(“Enter the marks scored in Hindi/Sanskrit:”))
sci = float(input(“Enter the marks scored in Science:”))
math = float(input(“Enter the marks scored in Math:”))
socialscience = float(input(“Enter the marks scored in socialscience:”))
total =eng+language2+sci+math+socialscience
per=(total*100)/500
print(“Total marks secured by the student out of 500”, total)
print (“Percentage secured by the student:”,per)
4. WRITE A PROGRAM TO CHECK WHETHER A GIVEN
CHARACTER IS AN UPPER CASE LETTER OR LOWER CASE
LETTER OR A DIGIT OR A SPECIAL CAHARACTER.
ch= input(“Enter any character:”)
if ch.isupper():
print (ch, “is an upper case letter”)
elif= ch.islower():
print(ch, “is a lower case letter:”)
elif ch.isdigit():
print(“ch”, is a digit)
elif= ch.isspace():
print(“ch”, is a space)
print(ch, “is a special character”)
5. WRITE A PROGRAM TO CHECK WHETHER THE GIVEN NUMBER
IS EVEN OR ODD.
num= int(input(“Enter a number greater than 0:”))
if num%2==0
print(“The given number:”, num, “is a even number”)
else:
print (“The given number:”, num, “is an odd number”)
6. WRITE A NUMBER TO FIND THE MAXIMUM NUMBER OUT OF
THREE NUMBER.
n1=int(input(“Enter the Number1:”))
n2 = int(input(“Enter the Number2:”))
n3= int(input(“Enter the Number3:”))
if n1>n2 and n1>n3:
print(n1, “Number1 is greater”)
elif n2>n1 and n2>n3:
print (n2, “Number2 is greater:”)
elif n3>n1 and n3>n2:
print (n3, “Number3 is greater:”)
else:
print (“All are same”)
7. WRITE A PROGRAM TO FIND THE FACTORIAL OF GIVEN
NUMBER.
n= int(input(“Enter any number:”)
i=1
fact=1
while i<=n:
fact=fact*i
i=i+1
print (“the factorial of”, n, “is:”, fact)
8. WRITE A PROGRAM TO PRINT TABLE OF NUMBER UPTO 10.
num= int(input(“Enter any number:”))
print (“Multipication table of”, num, “is:”)
for i in range (1,11):
print (num, ‘x’, i, ‘=’, num*i)
9. WRITE A PROGRAM TO GENERATE FOLLOWING PATTERN:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
n= int(input(“Enter n:”))
k=1
for i in range (1,n+1):
for j in range (1,i+1):
print(k, end= “”)
k+=1
Print()
10.WRITE A PROGRAM TO GENERATE A FOLLOWING PATTERN:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
rows = int(input(“Enter number of rows:”))
for i in range (rows):
for j in range (i+1):
print (j+1, end= “”)
print ()
11.WRITE A PROGRAM TO CREATE AN 2-DIM ARRAY.
import numpy as np
arr = np.array([[1,2] , [3,4]] [[5,6] , [7,8]])
arr
12. WRITE A PROGRAM TO ADD TO ARRAY.
import numpy as np
a= np.array([1,2,3])
b= np.array([4,5,6])
a+b
13.WRITE A PROGRAM TO CREATE A DATA FRAME TO STORE
DATA OF CANDIDATES WHO APPEARED IN INETRVIEWS. THE
DATA FRAME COLUMNS ARE NAME, SCORE, ATTEMPTS AND
QUALIFY (YES/NO). ASSIGN ROW INDEX ATR (001,002,003…….)
Import pandas as pd
d= {‘name’:[‘A’, ‘B’, ‘C’, ‘D’, ‘E’], ‘score’: [25,20,22,23,21], ‘attempts’:
[1,2,2,1,2], ‘qualified’ : [‘yes’ ,‘no’ ,‘yes’ ,‘no’ ,‘yes’]
df= pd.DataFrame(d,index=[ ‘c001’, ‘c002’, ‘c003’, ‘c004’, ‘c005’])
print(df)
14.WRITE A PROGRAM TO FIND MODE, MEAN AND MEDIAN.
import statistics
dataset =[5,9,7,4,2,6,8]
mean_easy=statistics.mean(dataset)
mean_easy()
dataset_median_even=[4,-5,8,6,9,4,7,-2]
sorted(dataset_median_even)
median_even=statistics.median(dataset_median_even)
median_even
dataset_median_odd=[4,-5,8,6,9,4,7,-2]
sorted(dataset_median_odd)
median_odd=statistics.median(dataset_median_odd)
median_odd
dataset_mode=[1,2,3,4,5,5,5,6,5,8,7,9]
mode=statistics.mode(dataset_mode)
mode
15. WRITE A PROGRAM TO ADD THE ELEMENTS OF TWO LIST.
import numpy as np
a=[1,2,4,6,8]
b=[4,5,6,2,10]
c=np.add(a,b)
print(c)
16.WRITE A PROGRAM TO DRAW A LINE CHART FOR THE
FOLLOWING POINTS (2,4)(3,9)(4,16)
from matplotlib import pyplot as plt
plt.plot([2,3,4], [4,9,16])
plt.xlabel(“x axis”)
plt.ylabel(“y axis”)
plt.show()
17.WRITE A PROGRAM TO DISPLAY A SCATTER CHART FOR THE
FOLLOWING POINTS (9,10)(8,3)(5,7)(6,18)
from matplotlib import pyplot as plt
%matplotlib inline
x=[9,8,5,6]
y=[10,3,7,18]
plt.scatter(x,y);
plt.title(‘scatter plot’)
plt.xlabel(‘y-axis’)
plt.ylabel(‘x-axis’)
plt.show()
18.WRITE A PROGRAM TO READ THE CSV FILE SAVED IN YOUR
SYSTEM AND DISPLAYS 5 ROWS.
import pandas as pd
marks =pd.read_csv(“c//user//ash//desktop//resultdata.csv”)
data=marks.1loc[0:5].values
print(data)
19. WRITE A PROGRAM TO READ IMAGE AND DISPLAY BY USING
PYTHON.
import cv2
img= cv2.imread (“image.jpg”)
cv2.imshow( “kk”, img)
cv2.waitKey(5000)
cv2.destroyWindow(“kk”)