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

Gr10 AI ProgramSourceCode

The document contains a series of Python programming assignments for Grade X, each with a specific task such as calculating average height, checking for prime numbers, and visualizing data using various plots. Each program includes source code and instructions for submission. The tasks range from basic input/output operations to data visualization and file handling using libraries like matplotlib and pandas.

Uploaded by

jaideep.zoom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Gr10 AI ProgramSourceCode

The document contains a series of Python programming assignments for Grade X, each with a specific task such as calculating average height, checking for prime numbers, and visualizing data using various plots. Each program includes source code and instructions for submission. The tasks range from basic input/output operations to data visualization and file handling using libraries like matplotlib and pandas.

Uploaded by

jaideep.zoom
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Grade X

Python Programs
Note: Write the program and submit with printout of source code and
output in a A4 size sheet.
Program 1: Write a program to find the average height of the class.
height=[140,134,166,150,154,172,180,137,144,160]
Source Code:
height=[140,134,166,150,154,172,180,137,144,160]
sum=0
avg=0
for i in height:
sum=sum+i
avg=sum/10
print("The average height is :",avg)

Program 2: Write a program to take a number from the user and check ‘whether
the number is prime number or not’.

Source code:
num=int(input(“Enter a number”))
if num>1:
For x in range(2,num):
if num%2==0:
print(num,” is not a prime number”)
Break
else:
print(num, “is a prime number”)
else:
print(num,”is not a prime number”)

Program 3: Write a program which can take password/input from the user and
check the correct password, which is ‘SECRET’. The user can enter the password
only three times and the system should print ‘You cannot enter the house after
that’.
Source code:
flag=0
for i in range(0,3):
pwd=input(“Enter the password”)
if pwd==’SECRET’:
print(“Welcome”)
flag=1
else:
print(“Wong password”)
if flag==0:
print(“You cannot enter the house”)

Program 4: Write a program to print today’s(current) date or today’s date and


time, based on user’s choice (using if..else statement).
Source code:
from datetime import date as d
import datetime as dt
button_pressed=0
button_pressed=input("Please press a button- 1: Today’s date and
2:datetime")
if button_pressed=="1":
print (d.today())
elif button_pressed=="2":
print(dt.datetime.now())
else:
print("Wrong input entered")

Program 5: Write a program to print area of a house. Area is given in the list
‘Area’.
area=[“hall”, 660, “bedroom”, 444.25, “kitchen”, 220.55, “dining”, 215.80,
“bathroom”, 110.33]
Source code:
area=['hall', 660, 'bedroom', 444.25, 'kitchen', 220.55, 'dining', 215.80,
'bathroom', 110.33]
print(area)
ar=input("Enter the portion for which you want to see area ")
if ar=="Hall":
print(area[1])
elif ar=="Bed":
print(area[3])
elif ar=="Kit":
print(area[5])
elif ar=="Liv":
print(area[7])
elif ar=="Bath":
print (area[9])
else:
print ("Wrong input")

Program 6: Write a program to create a bar chart. Import the required libraries
Maruti_cars=[‘Ertiga’,’Ignis’,’Dzire’,’Brezza’,’Baleno’]

Sales=[8897,6754,5655,4000,7500]

Source code:

import matplotlib.pyplot as plt


Maruti_cars=[‘Ertiga’, ’Ignis’ ,’Dzire’ , ’Brezza’ ,’Baleno’]

Sales=[8897,6754,5655,4000,7500]
plt.bar (Maruti_cars,Sales)
plt.xlabel(“Maruti_cars”)
plt.ylabel(“Sales”)
plt.title(“Maruti_cars and sales”)
#Rotate the x-axis labels for better readability
plt.xticks(rotation=45)
plt.show()
Program 7: Write a program to visualize a Line graph. Import the required
libraries
years_of_experience = [2,3,4,5,6]
salaries =[40000, 50000, 85000, 100000, 115000]

Source code:
import matplotlib.pyplot as plt
years_of_experience = [2,3,4,5,6]
salaries =[40000, 50000, 85000, 100000, 115000]
plt.plot (height, weight, marker='*')
plt.xlabel('years_of_experience')
plt.ylabel('salaries')
plt.title('Height and Weight')
plt.show()

Program 8: Write a program to visualize a Scatter plot. Import the required


libraries
height=[175,123,140,157,179]
weight=[59,45,55,62,66]
Source code:
import matplotlib.pyplot as plt
height=[175,123,140,157,179]
weight=[59,45,55,62,66]
plt.scatter(height, weight, marker='o')
plt.xlabel('Height')
plt.ylabel('Weight')
plt.title('Height and Weight')
plt.show()

Program 9: Write a program to visualize a histogram. Import the required libraries


Source code:
import matplotlib.pyplot as plt
import numpy as np
x=np.random.normal(170,10,235)
plt.hist(x)
plt.show()

Program 10: Write a program to do the following: Import the required libraries
a) Save the “healthcare_dataset.csv” file into a variable s.
Source code:
import pandas as pd
s=pd. read_csv("Z:\Grade 10\Grade 10 Lab Activities
\healthcare_dataset.csv")
print(s)

b) Print the top 5 rows of the file.


Source code:
print(s.head())

c) Print the top 12 rows of the file.


Source code:
print(s.head(12))

d) Sort the file in the ascending order of the column ‘age’ .


Source code:

import pandas as pd
s=pd.read_csv(r"C:\Users\Admin\Desktop\healthcare_dataset.csv")
sl=s.sort_values(by='Age',ascending=False)
print(sl)

Program 11: Write a program to do the following : Import the required libraries
a) Save the “JaipurFinalCleanData.csv” file into a variable s.
Source code:

import pandas as pd
s=pd. read_csv("Z:\Grade 10\Grade 10 Lab Activities
\healthcare_dataset.csv")
print(s)

b) Print the bottom 5 rows of the file.


Source code:
print(s.tail())

c) Print the bottom 15 rows of the file.


Source code:
print(s.tail(15))

d) Sort the file in the descending order of the column ‘meantempm’.


Source code
import pandas as pd
s=pd.read_csv(r"C:\Users\Admin\Desktop\JaipurFinalCleanData.csv")
sl=s.sort_values(by='meantempm',ascending=False)
print(sl)

Program 12: Write a program to upload an image of your favorite city in the
world on the screen and give a proper title to it.

Source code:
import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\London.jpg’)
plt.imshow(img)
plt.title(‘My Favorite City’)
plt.axes(‘off’)
plt.show()
Program 13: Write a program to upload an image of your favorite food and
display the picture in RGB color mode.
Source code:

import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread(‘D:\Pasta.jpg’)
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title(‘My Favorite Food’)
plt.axes(‘off’)
plt.show()

Program 14: Write a program to upload an image of your favorite pet and display
the picture in grayscale mode.
Source code:

import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\Dog.jpg’,0)
plt.imshow (img, cmap=’gray’)
plt.title(‘My Pet’)
plt.axes(‘off’)
plt.show()

Program 15: Write a program to upload an image of your favorite pet and crop
the image.
Source code:

import cv2
from matplotlib import pyplot as plt
import numpy as np
img=cv2.imread (‘D:\Dog.jpg’,0)
roi=img[20:230,120:372]
plt.imshow(cv2.cvtColor(roi,cv2.COLOR_BGR2RGB)
plt.title(‘My Pet’)
plt.axes(‘off’)
plt.show()

______________________________________________________________________

You might also like