2. a. Develop a program to generate Fibonacci sequence of length (N).
Read N from
the console.
N = int(input("Enter the length of the Fibonacci sequence: "))
fibonacci = []
if N <= 0:
print("Please enter a positive integer.")
else:
a, b = 0, 1
for i in range(N):
[Link](a)
a, b = b, a + b
print("Fibonacci sequence of length", N, "is:")
print(fibonacci)
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)
# Inserting an element at a specific position
my_list.insert(2, 25)
print("After Inserting 25:", my_list)
# Removing an element (by value)
my_list.remove(30)
print("After Removing 30:", my_list)
# Appending an element at the end
my_list.append(50)
print("After Appending 50:", my_list)
# Displaying the length of the list
print("Length of the List:", len(my_list))
# Popping an element (last element by default)
popped = my_list.pop()
print("After Popping element:", my_list)
print("Popped Element:", popped)
# Clearing the entire list
my_list.clear()
print("After Clearing the List:", my_list)