Class X Python Programs (1) - 1
Class X Python Programs (1) - 1
import numpy as np
import statistics as stat
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
mn = np.mean(speed)
mdn = np.median(speed)
md = stat.mode(speed)
print(mn)
print(mdn)
print(md)
4. Write a program to display a scatter chart for the following points (2,5),
(9,10),(8,3),(5,7),(6,18).
6. Read csv file saved in your system and display its information
import pandas as pd
df=pd.read_csv(‘C:\JaipurFinalCleanData.csv’)
print(df.head(10))
print(df.shape)
print(df.dtypes)
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('c:\man.jpg')
plt.imshow(img)
plt.title('Man')
plt.axis('off')
plt.show()
8. Write a program to read an image and identify its shape using Python
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('c:\man.jpg')
plt.imshow(img)
plt.title('Man')
plt.axis('off')
plt.show()
print(img.shape)
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('man.jpg',0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.title('Man')
plt.axis('off')
plt.show()
subjects=["Eng","Hindi","Sanskrit","Maths", "Science","Social","AI"]
plt.pie(marks,labels=subjects, autopct='%1.2f%%')
plt.show()
12. Python program to find the factorial of a number provided by the user.
# To take input from the user
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)
14. Python program to check if two strings are anagrams using sorted()
str1 = "Race"
str2 = "Care"
# convert both the strings into
lowercasestr1 = str1.lower()
str2 = str2.lower()
# check if length is same
if(len(str1) == len(str2)):
# sort the strings sorted_str1 = sorted(str1)sorted_str2 = sorted(str2)
# if sorted char arrays are same
if(sorted_str1 == sorted_str2):
print(str1 + " and " + str2 + " are anagram.")
else:
print(str1 + " and " + str2 + " are not anagram.")
else:
print(str1 + " and " + str2 + " are not anagram.")
****