0% found this document useful (0 votes)
8 views2 pages

Python Lab

The document contains Python programs for various list operations, including inserting, removing, appending, displaying length, popping, and clearing a list. It also includes a program to read N numbers from the console and calculate their mean, variance, and standard deviation. Additionally, there is a program to read a multi-digit number and print the frequency of each digit.

Uploaded by

dbossmonster
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Python Lab

The document contains Python programs for various list operations, including inserting, removing, appending, displaying length, popping, and clearing a list. It also includes a program to read N numbers from the console and calculate their mean, variance, and standard deviation. Additionally, there is a program to read a multi-digit number and print the frequency of each digit.

Uploaded by

dbossmonster
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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")

You might also like