2.
b) Write a python program to create a list and perform the following operations:
• Inserting an element
• Removing an element
• Appending an element
• Displaying the length of the list
• Popping an element
• Clearing the list
my_list = [10, 20, 30, 40]
print("Initial List:", my_list)
my_list.insert(2, 25) # Insert 25 at index 2
print("After Inserting 25 at index 2:", my_list)
my_list.append(50)
print("After Appending 50:", my_list)
my_list.remove(20)
print("After Removing 20:", my_list)
print("Length of the list:", len(my_list))
popped_element = my_list.pop()
print("Popped Element:", popped_element)
print("After Popping:", my_list)
my_list.clear()
print("After Clearing the list:", my_list)
3 a. Read N numbers from the console and create a list. Develop a python program to print
mean, variance and standard deviation with suitable messages.
n = int(input("Enter the number of elements: "))
numbers = []
for i in range(n):
value = float(input(f"Enter number {i+1}: "))
[Link](value)
mean = sum(numbers) / n
variance = sum((x - mean) ** 2 for x in numbers) / n
std_dev = variance ** 0.5
print("\nEntered List:", numbers)
print("Mean =", mean)
print("Variance =", variance)
print("Standard Deviation =", std_dev)
3 b. Read a multi-digit number (as chars) from the console. Develop a program to print the
frequency of each digit with a suitable message.
num = input("Enter a multi-digit number: ")
freq = {}
for digit in num:
if digit in freq:
freq[digit] += 1
else:
freq[digit] = 1
print("\nDigit Frequency:")
for digit in sorted(freq):
print(f"Digit {digit} occurs {freq[digit]} times")