Python Programs Solutions
Python Programs Solutions
data = [1, 2, 3, 4, 5, 5, 6]
mean = np.mean(data)
median = np.median(data)
mode = stats.mode(data)
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode.mode[0])
x = [2, 9]
y = [5, 10]
plt.plot(x, y)
plt.title("Line Chart")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
x = [2, 9, 8, 5, 6]
y = [5, 10, 3, 7, 18]
plt.scatter(x, y)
plt.title("Scatter Chart")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
5. Read CSV file and display 10 rows
import pandas as pd
df = pd.read_csv('yourfile.csv')
print(df.head(10))
df = pd.read_csv('yourfile.csv')
print(df.info())
image = cv2.imread('yourimage.jpg')
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title("Image Display")
plt.axis('off')
plt.show()
image = cv2.imread('yourimage.jpg')
print("Image shape:", image.shape)
10. Read two numbers and arithmetic operator and display the computed result
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
if num2 != 0:
result = num1 / num2
else:
result = "Cannot divide by zero"
else:
result = "Invalid operator"
print("Result:", result)