0% found this document useful (0 votes)
25 views3 pages

Python Practical Programs for Class X

The document contains practical programming exercises for Class X students at Dayawati Modi Public School. It includes tasks such as adding elements of lists, calculating statistical measures, finding factorials, creating line and scatter charts, reading CSV files, reversing strings, and displaying images. Each task is accompanied by Python code examples demonstrating the required functionality.

Uploaded by

mady4e
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)
25 views3 pages

Python Practical Programs for Class X

The document contains practical programming exercises for Class X students at Dayawati Modi Public School. It includes tasks such as adding elements of lists, calculating statistical measures, finding factorials, creating line and scatter charts, reading CSV files, reversing strings, and displaying images. Each task is accompanied by Python code examples demonstrating the required functionality.

Uploaded by

mady4e
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

DAYAWATI MODI PUBLIC SCHOOL(MODINAGAR)

CLASS X (PRACTICAL PROGRAMS)

# 1. WAP to add the elements of the two lists.


s1=[32,45,40]
s2=[35,30,42,38]
print(s1,len(s1))
print(s2,len(s2))
all=s1+s2
print(all,len(all))

# 2. WAP to calculate mean, median, mode using numpy of the following list
of distance travelled by a car in a week.
import statistics
d=[95,90,49,71,90,100,55]
m1=[Link](d)
m2=[Link](d)
m3=[Link](d)
print("the mean is:",m1)
print("the median is:",m2)
print("the mode is:",m3)

# [Link] a python code to take the input of a number n and then find display
its factorial(n!).
n=int(input("Enter a number:"))
if(n==0):
print("factorial of 1=", 0)
f=1
for i in range(1,n+1):
f=f*i
print("factorial of number is",f)

# 4. WAP to display line chart fom(2,5) to (9,10).


import [Link] as plt
import numpy as np
x=[Link]([2,3,9,10])
y=x*2
[Link](x,y)
[Link]("x-axis")
[Link]("y-axis")
[Link]("line chart")
[Link]()
# 5. WAP to display a scatter chart for the following points (2,5), (9,10), (8,3),
(5,7), (6,18).
import [Link] as plt
import numpy as np
(2,5),(9,10),(8,3),(5,7),(6,18)
x=[Link]([2,9,8,5,6])
y=[Link]([5,10,3,7,18])
[Link]("x-axis")
[Link]("y-axis")
[Link]("Scatter chart")
[Link](x,y)
[Link]()

# [Link] CSV file saved in your system and display 10 rows.


import panda as pd
df=pd.read_csv('D:/[Link]')
print([Link](10))

# [Link] CSV file saved in your system and display its information.
import panda as pd
df=pd.read_csv('D:/[Link]')
print(df)

# [Link] to input a string and display the string in the reverse order.
def reverse_string(str):
str1=" "
for i in str:
str1=i+str1
return str1
str="ArtificialIntelligence"
print("The original string is:",str)
print("The reverse string is",reverse_string(str))

# 9. Write a program to read an image and display using python.


import cv2
from matplotlib import pyplot as plt
import numpy as np
image = [Link]('D:/[Link]')
height,width,channels = [Link]
print("Image shape:")
print("Height:",height)
print("Width:",width)
print("Number of channels:",channels)

# [Link] to read an image and display using python.


import cv2
from matplotlib import pyplot as plt
import numpy as np
img = cv2. imread('D:/[Link]')
[Link](img)
[Link]('My favourite city')
[Link]('off')
[Link]

Common questions

Powered by AI

To read and display the first 10 rows of a CSV file in Python, the 'pandas' library must be used. Import it using `import pandas as pd`. Read the CSV file using `df=pd.read_csv('D:/data.csv')`. To display the first 10 rows, use the DataFrame method `df.head(10)` which outputs the first 10 rows of data from the CSV file .

Python provides several advantages for data processing, including a vast array of libraries and tools like pandas for efficient data manipulation and matplotlib for comprehensive data visualization. This ecosystem enables users to execute complex data tasks with concise and readable code. Python's integration capability with other software systems and its strong community support further augment its utility in processing diverse datasets efficiently .

To create a line chart in Python using Matplotlib, first import `matplotlib.pyplot` as `plt` and `numpy` as `np`. Define your data points in arrays, e.g., `x=np.array([2,3,9,10])` and calculate the corresponding y-values, for example, `y=x*2`. Use `plt.plot(x,y)` to create the line chart. Label the axes with `plt.xlabel('x-axis')` and `plt.ylabel('y-axis')`, set a title with `plt.title('line chart')`, and finally, display the chart using `plt.show()` .

To reverse a string in Python, a function can be created using a for loop to iterate over the string. Define the function `def reverse_string(str):`, initialize an empty string `str1`, and iterate through the characters of the input string, concatenating them in reverse order with `str1=i+str1`. Finally, return `str1`. This constructs the reversed string by adding each character to the front of the accumulating result .

To display metadata information about a CSV file in Python, including data types and column counts, use the pandas library by importing it with `import pandas as pd`. Read the CSV file with `df=pd.read_csv('D:/data.csv')`, and then call `df.info()`, which prints a concise summary of the DataFrame including index dtype, column dtypes, non-null values, and memory usage .

To plot a scatter chart in Python, we need to use the matplotlib library. Begin by importing the necessary modules: `import matplotlib.pyplot as plt` and `import numpy as np`. Define the data points as arrays, like `x=np.array([2,9,8,5,6])` and `y=np.array([5,10,3,7,18])`. Then, label the axes with `plt.xlabel('x-axis')` and `plt.ylabel('y-axis')`, set the chart title with `plt.title('Scatter chart')`, and use `plt.scatter(x,y)` to create the scatter plot. Finally, display the plot using `plt.show()` .

Use the OpenCV and Matplotlib libraries to read and display an image in Python. Import `cv2` and `from matplotlib import pyplot as plt`. Load the image file using `cv2.imread('D:/london.jpg')` to read the image, and to display, use `plt.imshow(img)`, set a title with `plt.title('My favourite city')`, and remove axes using `plt.axis('off')`. Finally, display the image with `plt.show()` .

A line chart is preferable over a scatter chart when the primary goal is to display trends over time or continuous data relationships, as it effectively shows connections between points. Conversely, scatter charts are ideal for illustrating the correlation or distribution of two variables without inherent ordered relationships . Line charts provide a clearer view of the flow or progression of data, whereas scatter charts offer a visual representation of data distribution or clustering without suggesting continuity or order .

To calculate the mean, median, and mode of a dataset in Python, the 'statistics' module can be used. First, import the module using `import statistics`. Then, for a given list `d`, compute the mean with `statistics.mean(d)`, the median with `statistics.median(d)`, and the mode with `statistics.mode(d)` .

To calculate the factorial of a number in Python, use a function that employs a for loop. Prompt for user input with `n=int(input('Enter a number:'))`. Initialize a variable `f=1` for storing the result. Iterate via a for loop `for i in range(1,n+1):`, multiplying `f` by `i` in each iteration with `f=f*i`. Print the result after the loop completes. This logic accumulates the product of all positive integers up to `n`, effectively computing the factorial .

You might also like