python programs
python programs
print("Name:", name)
print("Class:", class_name)
print('*' * i)
-------------------------------------
---------------------------------------
n = 5 # Number of rows
print('*' * i)
---------------------------------------
---------------------------------------------
for i in range(n):
print('*' * n)
------------------------------------
n = 5 # Number of rows
# Print spaces
print(j, end='')
print(j, end='')
print()
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
5. Create a list in Python of children selected for science quiz with following namesArjun, Sonakshi,
Vikram, Sandhya, Sonal, Isha, Kartik
children.remove("Vikram")
children.append("Jay")
del children[1]
--------------------------------------------------------------------------------------------------------------------------------
○ print the elements from second to fourth position using positive indexing
○ print the elements from position third to fifth using negative indexing.
# 2. Print the elements from second to fourth position using positive indexing
# Positive indexing: Start from index 1 (second element) to index 3 (fourth element)
print("Elements from second to fourth position:", num[1:4])
# 3. Print the elements from third to fifth position using negative indexing
# Negative indexing: Start from -4 (third element from the end) to -2 (fifth element from the end)
function. Now sort the final list in ascending order and print it.
# Initial list
List_1.sort()
print(List_1)
9. Input a number and check if the number is positive, negative or zero and display an appropriate
message.
i=1
print(i)
i += 1
numbers = [1, 2, 3, 4, 5]
total_sum = 0
# Iterate through the list and add each number to the sum
total_sum += num
12. Write a program to calculate mean, median and mode using Numpy
import numpy as np
def calculate_statistics(data):
mean = np.mean(data)
median = np.median(data)
# Example data
data = [1, 2, 2, 3, 4, 4, 4, 5, 6]
# Calculate statistics
print(f"Mean: {mean}")
print(f"Median: {median}")
print(f"Mode: {mode}")
x_values = [2, 9]
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.xlim(0, 10)
plt.ylim(0, 15)
plt.grid()
plt.show()
14. Write a program to display a scatter chart for the following points (2,5),
(9,10),(8,3),(5,7),(6,18).
points = [(2, 5), (9, 10), (8, 3), (5, 7), (6, 18)]
plt.figure(figsize=(8, 6))
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# Show grid
plt.grid(True)
plt.show()
import pandas as pd
file_path = 'your_file.csv'
data = pd.read_csv(file_path)
print(data.head(10))
● Read csv file saved in your system and display its information
import pandas as pd
file_path = 'your_file.csv'
data = pd.read_csv(file_path)
print(data.info())
print("\nFirst 5 Rows:")
print(data.head())
image_path = 'your_image.jpg'
image = Image.open(image_path)
plt.imshow(image)
plt.show()
16. Write a program to read an image and identify its shape using Python
image_path = 'your_image.jpg'
image = Image.open(image_path)