2. a. Develop a program to generate Fibonacci sequence of length (N).
Read N
from the console.
num = int(input("Enter the Fibonacci sequence length to be generated : "))
firstTerm = 0
secondTerm = 1
print("The Fibonacci series with", num, "terms is :")
print(firstTerm, secondTerm, end=" ")
for i in range(2,num):
curTerm = firstTerm + secondTerm
print(curTerm, end=" ")
firstTerm = secondTerm
secondTerm = curTerm
Output:-
b. Write a python program to create a list and perform the following
operations • Inserting an element
1. Removing an element
2. Appending an element
3. Displaying the length of the list
4. Popping an element
5. Clearing the list
1) Removing an element
l1 = [10, 20, 30, 40, 50]
print("Original list:", l1)
try:
x = int(input("Enter the element to be removed: "))
if x in l1:
[Link](x)
print("Element removed successfully!")
print("Updated list:", l1)
else:
print("Specified element is not available.")
except ValueError:
print("Please enter a valid number only.")
Output:-
2) j
# list1
list1 = ['Bti', 'College', 'Bangalore']
# list2
list2 = ['karnataka', 'India']
# appending
[Link](list2)
print('Updated animals list: ', list1)
Output:-
3)Displaying the length of the list
print("Enter the List")
my_list = list(input())
list_length = len(my_list)
# Print the length
print(f"The length of the list is: {list_length}")
Output:-
4)Popping an Element
print("Enter the List")
my_list = list(input().split())
list1=my_list
print("list1",list1)
pop_list = list(input())
print([Link]()) #60
print("list1",list1)
Output:-
5)Clearing the list
print("Enter the List")
my_list = list(input().split())
list1=my_list
print("list1",list1)
[Link]()
print("cleared element",list1)
Output:-