Computer Science, asked by Anonymous, 3 months ago

give me the correct answer of any of the questions
❌spam are not allowed❌ PLEASE it is a request

chapter 4 [ working with lists and dictionaries ] class 11

programming questions:

5. Write a program to read a list of elements. Modify this
list so that it does not contain any duplicate elements i.e.
all elements occurring multiple times in the list should
appear only once.
6. Write a program to create a list of elements. Input an
element from the user that has to be inserted in the list.
Also input the position at which it is to be inserted.
7. Write a program to read elements of a list and do the
following
a) The program should ask for the position of the
element to be deleted from the list and delete the
element at the desired position in the list.
b) The program should ask for the value of the element
to be deleted from the list and delete this value from
the list.

Answers

Answered by Equestriadash
10

5.

n = int(input("Enter the number of elements you'd like to add: "))

print()

l = list()

for i in range(n):

   x = eval(input("Enter the element: "))

   l.append(x)

   print()

print()

print(l, "is your given list.")

print()

for i in l:

   if l.count(i) > 1:

       l.remove(i)

print(l, "is the new list.")

6.

n = int(input("Enter the number of elements you'd like to add: "))

print()

l = list()

for i in range(n):

   x = eval(input("Enter the element: "))

   l.append(x)

   print()

print()

print(l, "is your given list.")

print()

ne = eval(input("Enter the element that you'd like to insert into the list: "))

nep = int(input("Enter the position at which you'd like to insert the element: "))

l.insert(nep, ne)

print()

print(l, "is the new list.")

7.

n = int(input("Enter the number of elements you'd like to add: "))

print()

l = list()

for i in range(n):

   x = eval(input("Enter the element: "))

   l.append(x)

   print()

print()

print(l, "is your given list.")

print()

dep = int(input("Enter the position of the element that you'd like to remove from the list: "))

print()

if dep <= len(l):

   del l[dep]

   print(l, "is the updated list.")

   print()

else:

   print("Invalid index position.")

   print()

de = eval(input("Enter the element that you'd like to remove from the list: "))

print()

if de in l:

   l.remove(de)

   print(l, "is the updated list.")

else:

   print("No such value.")


Equestriadash: Thanks for the Brainliest! ^_^"
Similar questions