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

Python Program 2

The document provides two Python programs: the first generates a Fibonacci sequence of a specified length N, while the second performs various operations on a list, including inserting, removing, appending elements, displaying the list's length, popping an element, and clearing the list. Both programs include user input and print statements to display the results of the operations. The examples demonstrate basic list manipulation and Fibonacci sequence generation in Python.

Uploaded by

ecobliss22
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)
16 views2 pages

Python Program 2

The document provides two Python programs: the first generates a Fibonacci sequence of a specified length N, while the second performs various operations on a list, including inserting, removing, appending elements, displaying the list's length, popping an element, and clearing the list. Both programs include user input and print statements to display the results of the operations. The examples demonstrate basic list manipulation and Fibonacci sequence generation in Python.

Uploaded by

ecobliss22
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. 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)

You might also like