Python Lab Activities-Combined
Python Lab Activities-Combined
list.extend({7,52,4 1})
print(list)
list.insert(0,100)
print(list)
list.remove(8)
print(list)
list.pop(7)
print(list)
list = [5, 8, 12, 18, 90, 512, 88, 61, 88, 96, 100, 0, 68]
print(list.count(88))
print(list.index(5))
list.sort()
print(list)
list.sort(reverse=True)
print(list)
list.reverse()
print(list)
Question :-4
Write a python program that finds the factorial of a given number.
Solution:-
Write a Python program that uses a lambda function to filter even numbers from a list of integers.
solution:-
Write a Python program that creates a class called Student with attributes like name, age, and grade.
Create objects of this class and display their details.
Solution:-
class Student:
self.name = name
self.age = age
self.grade = grade
def display_details(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
print(f"Grade: {self.grade}")
print('-' * 30)
student1.display_details()
student2.display_details()
student3.display_details()
Question:- 8
Write a Python program that handles a division by zero exception and always executes a cleanup
message in the finally block.
Solution:-
try:
except ZeroDivisionError:
finally:
Write a Python program to read content from a text file, modify the content (convert to uppercase),
and write it back to a new file.
Solution:-
input_filename = 'input.txt'
output_filename = 'output.txt'
try:
content = infile.read()
modified_content = content.upper()
outfile.write(modified_content)
except FileNotFoundError:
except Exception as e: